Skip to content

Commit 4342e6a

Browse files
committed
[AMDGPU] Handle CreateBinOp not returning BinaryOperator
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 89c5c3b commit 4342e6a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -O1 < %s | FileCheck -check-prefix=GCN %s
3+
4+
define amdgpu_kernel void @kernel() {
5+
; GCN-LABEL: kernel:
6+
; GCN: ; %bb.0: ; %entry
7+
; GCN-NEXT: s_endpgm
8+
entry:
9+
%B = srem <32 x i64> zeroinitializer, zeroinitializer
10+
ret void
11+
}

0 commit comments

Comments
 (0)