[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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user