[AMDGPU] Handle CreateBinOp not returning BinaryOperator (#137791)

AMDGPUCodeGenPrepareImpl::visitBinaryOperator() calls
Builder.CreateBinOp() and casts the resulting Value as a BinaryOperator
without checking, leading to an assert failure in a case found by
fuzzing. In this case, the operands are constant and CreateBinOp does
constant folding so returns a Constant instead of a BinaryOperator.
This commit is contained in:
anjenner
2025-05-29 18:10:35 +01:00
committed by GitHub
parent cb648ba970
commit a36cb01ea7
2 changed files with 13 additions and 1 deletions

View File

@@ -1684,7 +1684,10 @@ bool AMDGPUCodeGenPrepareImpl::visitBinaryOperator(BinaryOperator &I) {
// return the new value. Just insert a scalar copy and defer
// expanding it.
NewElt = Builder.CreateBinOp(Opc, NumEltN, DenEltN);
Div64ToExpand.push_back(cast<BinaryOperator>(NewElt));
// CreateBinOp does constant folding. If the operands are constant,
// it will return a Constant instead of a BinaryOperator.
if (auto *NewEltBO = dyn_cast<BinaryOperator>(NewElt))
Div64ToExpand.push_back(NewEltBO);
}
}

View File

@@ -10094,3 +10094,12 @@ define i64 @udiv_i64_9divbits(i8 %size) {
%div = udiv i64 %num, 10
ret i64 %div
}
define <2 x i64> @srem_zero_zero() {
; GCN-LABEL: kernel:
; GCN: ; %bb.0: ; %entry
; GCN-NEXT: s_endpgm
entry:
%B = srem <2 x i64> zeroinitializer, zeroinitializer
ret <2 x i64> %B
}