Skip to content

Commit df91a02

Browse files
anjennersvkeerthy
authored andcommitted
[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.
1 parent ea2b77a commit df91a02

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,10 @@ bool AMDGPUCodeGenPrepareImpl::visitBinaryOperator(BinaryOperator &I) {
16841684
// return the new value. Just insert a scalar copy and defer
16851685
// expanding it.
16861686
NewElt = Builder.CreateBinOp(Opc, NumEltN, DenEltN);
1687-
Div64ToExpand.push_back(cast<BinaryOperator>(NewElt));
1687+
// CreateBinOp does constant folding. If the operands are constant,
1688+
// it will return a Constant instead of a BinaryOperator.
1689+
if (auto *NewEltBO = dyn_cast<BinaryOperator>(NewElt))
1690+
Div64ToExpand.push_back(NewEltBO);
16881691
}
16891692
}
16901693

llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-idiv.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10094,3 +10094,12 @@ define i64 @udiv_i64_9divbits(i8 %size) {
1009410094
%div = udiv i64 %num, 10
1009510095
ret i64 %div
1009610096
}
10097+
10098+
define <2 x i64> @srem_zero_zero() {
10099+
; GCN-LABEL: kernel:
10100+
; GCN: ; %bb.0: ; %entry
10101+
; GCN-NEXT: s_endpgm
10102+
entry:
10103+
%B = srem <2 x i64> zeroinitializer, zeroinitializer
10104+
ret <2 x i64> %B
10105+
}

0 commit comments

Comments
 (0)