[PATCH] D80207: GlobalISel: Fix IRTranslator for constantexpr selects
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 19 06:28:34 PDT 2020
arsenm created this revision.
arsenm added reviewers: aemerson, paquette, aditya_nandakumar, gargaroff, kerbowa, foad.
Herald added subscribers: hiraditya, rovka, nhaehnle, wdng, jvesely.
Herald added a project: LLVM.
This was assuming a select is always an instruction, which is not
true.
https://reviews.llvm.org/D80207
Files:
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-constantexpr.ll
Index: llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-constantexpr.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-constantexpr.ll
@@ -0,0 +1,39 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -stop-after=irtranslator -o - %s | FileCheck %s
+
+ at gint = external addrspace(1) global i8, align 4
+
+; Technically we should be able to fold away the compare to true, but
+; currently constexpr doesn't understand null in non-0 address spaces.
+define amdgpu_kernel void @constantexpr_select_0() {
+ ; CHECK-LABEL: name: constantexpr_select_0
+ ; CHECK: bb.1 (%ir-block.0):
+ ; CHECK: [[GV:%[0-9]+]]:_(p1) = G_GLOBAL_VALUE @gint
+ ; CHECK: [[C:%[0-9]+]]:_(p1) = G_CONSTANT i64 0
+ ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[GV]](p1), [[C]]
+ ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
+ ; CHECK: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
+ ; CHECK: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ICMP]](s1), [[C1]], [[C2]]
+ ; CHECK: [[DEF:%[0-9]+]]:_(p1) = G_IMPLICIT_DEF
+ ; CHECK: G_STORE [[SELECT]](s32), [[DEF]](p1) :: (store 4 into `i32 addrspace(1)* undef`, addrspace 1)
+ ; CHECK: S_ENDPGM 0
+ store i32 select (i1 icmp eq (i8 addrspace(1)* @gint, i8 addrspace(1)* null), i32 1, i32 0), i32 addrspace(1)* undef, align 4
+ ret void
+}
+
+define amdgpu_kernel void @constantexpr_select_1() {
+ ; CHECK-LABEL: name: constantexpr_select_1
+ ; CHECK: bb.1 (%ir-block.0):
+ ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 1024
+ ; CHECK: [[INTTOPTR:%[0-9]+]]:_(p1) = G_INTTOPTR [[C]](s64)
+ ; CHECK: [[GV:%[0-9]+]]:_(p1) = G_GLOBAL_VALUE @gint
+ ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[INTTOPTR]](p1), [[GV]]
+ ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
+ ; CHECK: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
+ ; CHECK: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ICMP]](s1), [[C1]], [[C2]]
+ ; CHECK: [[DEF:%[0-9]+]]:_(p1) = G_IMPLICIT_DEF
+ ; CHECK: G_STORE [[SELECT]](s32), [[DEF]](p1) :: (store 4 into `i32 addrspace(1)* undef`, addrspace 1)
+ ; CHECK: S_ENDPGM 0
+ store i32 select (i1 icmp eq (i8 addrspace(1)* @gint, i8 addrspace(1)* inttoptr (i64 1024 to i8 addrspace(1)*)), i32 1, i32 0), i32 addrspace(1)* undef, align 4
+ ret void
+}
Index: llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -1010,10 +1010,11 @@
ArrayRef<Register> Op0Regs = getOrCreateVRegs(*U.getOperand(1));
ArrayRef<Register> Op1Regs = getOrCreateVRegs(*U.getOperand(2));
- const SelectInst &SI = cast<SelectInst>(U);
uint16_t Flags = 0;
- if (const CmpInst *Cmp = dyn_cast<CmpInst>(SI.getCondition()))
- Flags = MachineInstr::copyFlagsFromInstruction(*Cmp);
+ if (const SelectInst *SI = dyn_cast<SelectInst>(&U)) {
+ if (const CmpInst *Cmp = dyn_cast<CmpInst>(SI->getCondition()))
+ Flags = MachineInstr::copyFlagsFromInstruction(*Cmp);
+ }
for (unsigned i = 0; i < ResRegs.size(); ++i) {
MIRBuilder.buildSelect(ResRegs[i], Tst, Op0Regs[i], Op1Regs[i], Flags);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80207.264878.patch
Type: text/x-patch
Size: 3320 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200519/7e5bec21/attachment.bin>
More information about the llvm-commits
mailing list