Skip to content

Commit

Permalink
GlobalISel: Guard return in llvm::getIConstantSplatVal (#71989)
Browse files Browse the repository at this point in the history
getIConstantVRegValWithLookThrough could return NULL.
  • Loading branch information
changpeng committed Nov 14, 2023
1 parent d2fd110 commit 011c9ee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/GlobalISel/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
...

0 comments on commit 011c9ee

Please sign in to comment.