[llvm] a36cb01 - [AMDGPU] Handle CreateBinOp not returning BinaryOperator (#137791)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 29 10:10:38 PDT 2025
Author: anjenner
Date: 2025-05-29T19:10:35+02:00
New Revision: a36cb01ea7750373739c206f86abcce0dbf9df5f
URL: https://github.com/llvm/llvm-project/commit/a36cb01ea7750373739c206f86abcce0dbf9df5f
DIFF: https://github.com/llvm/llvm-project/commit/a36cb01ea7750373739c206f86abcce0dbf9df5f.diff
LOG: [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.
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-idiv.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
index 52177a2523bcb..277e08099684b 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
@@ -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);
}
}
diff --git a/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-idiv.ll b/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-idiv.ll
index 8e16889c72e65..b7097a9557b75 100644
--- a/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-idiv.ll
+++ b/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-idiv.ll
@@ -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
+}
More information about the llvm-commits
mailing list