[llvm] 011c9ee - GlobalISel: Guard return in llvm::getIConstantSplatVal (#71989)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 14 12:23:59 PST 2023
Author: Changpeng Fang
Date: 2023-11-14T12:23:54-08:00
New Revision: 011c9eeb9a42e35b56e7fa9c8f6ea105fe87f36a
URL: https://github.com/llvm/llvm-project/commit/011c9eeb9a42e35b56e7fa9c8f6ea105fe87f36a
DIFF: https://github.com/llvm/llvm-project/commit/011c9eeb9a42e35b56e7fa9c8f6ea105fe87f36a.diff
LOG: GlobalISel: Guard return in llvm::getIConstantSplatVal (#71989)
getIConstantVRegValWithLookThrough could return NULL.
Added:
llvm/test/CodeGen/AMDGPU/GlobalISel/amdgpu-prelegalizer-combiner-crash.mir
Modified:
llvm/lib/CodeGen/GlobalISel/Utils.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index 473c3f452f8b1d9..eaf829f562b2dc9 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -1116,9 +1116,9 @@ std::optional<APInt>
llvm::getIConstantSplatVal(const Register Reg, const MachineRegisterInfo &MRI) {
if (auto SplatValAndReg =
getAnyConstantSplat(Reg, MRI, /* AllowUndef */ false)) {
- std::optional<ValueAndVReg> ValAndVReg =
- getIConstantVRegValWithLookThrough(SplatValAndReg->VReg, MRI);
- return ValAndVReg->Value;
+ if (std::optional<ValueAndVReg> ValAndVReg =
+ getIConstantVRegValWithLookThrough(SplatValAndReg->VReg, MRI))
+ return ValAndVReg->Value;
}
return std::nullopt;
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/amdgpu-prelegalizer-combiner-crash.mir b/llvm/test/CodeGen/AMDGPU/GlobalISel/amdgpu-prelegalizer-combiner-crash.mir
new file mode 100644
index 000000000000000..7c50071e77da536
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/amdgpu-prelegalizer-combiner-crash.mir
@@ -0,0 +1,26 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 3
+# RUN: llc -march=amdgcn -mcpu=gfx1030 -run-pass amdgpu-prelegalizer-combiner %s -o - | FileCheck -check-prefix=GCN %s
+
+---
+name: non_inlineable_imm_splat
+body: |
+ bb.1:
+ liveins: $vgpr0
+
+ ; GCN-LABEL: name: non_inlineable_imm_splat
+ ; GCN: liveins: $vgpr0
+ ; GCN-NEXT: {{ $}}
+ ; GCN-NEXT: [[COPY:%[0-9]+]]:_(<2 x s16>) = COPY $vgpr0
+ ; GCN-NEXT: [[C:%[0-9]+]]:_(s16) = G_FCONSTANT half 0xH4200
+ ; GCN-NEXT: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x s16>) = G_BUILD_VECTOR [[C]](s16), [[C]](s16)
+ ; GCN-NEXT: [[SUB:%[0-9]+]]:_(<2 x s16>) = G_SUB [[COPY]], [[BUILD_VECTOR]]
+ ; GCN-NEXT: $vgpr0 = COPY [[SUB]](<2 x s16>)
+ ; GCN-NEXT: SI_RETURN implicit $vgpr0
+ %0:_(<2 x s16>) = COPY $vgpr0
+ %2:_(s16) = G_FCONSTANT half 0xH4200
+ %1:_(<2 x s16>) = G_BUILD_VECTOR %2(s16), %2(s16)
+ %3:_(<2 x s16>) = G_SUB %0, %1
+ $vgpr0 = COPY %3(<2 x s16>)
+ SI_RETURN implicit $vgpr0
+
+...
More information about the llvm-commits
mailing list