[PATCH] D80209: GlobalISel: Copy correct flags to select
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 19 07:00:32 PDT 2020
arsenm created this revision.
arsenm added reviewers: aemerson, aditya_nandakumar, paquette, foad, kerbowa.
Herald added subscribers: hiraditya, rovka, wdng.
Herald added a project: LLVM.
This was looking for a compare condition, and copying the compare
flags. I don't think this was ever correct outside of certain min/max
patterns which aren't checked, but this probably predates select
instructions having fast math flags.
https://reviews.llvm.org/D80209
Files:
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
Index: llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
===================================================================
--- llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
+++ llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
@@ -962,6 +962,31 @@
ret i32 %res
}
+; CHECK-LABEL: name: test_select_flags
+; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
+; CHECK: [[TRUNC:%[0-9]+]]:_(s1) = G_TRUNC [[COPY]](s32)
+; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY $s0
+; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY $s1
+; CHECK: [[SELECT:%[0-9]+]]:_(s32) = nnan G_SELECT [[TRUNC]](s1), [[COPY1]], [[COPY2]]
+define float @test_select_flags(i1 %tst, float %lhs, float %rhs) {
+ %res = select nnan i1 %tst, float %lhs, float %rhs
+ ret float %res
+}
+
+; Don't take the flags from the compare condition
+; CHECK-LABEL: name: test_select_cmp_flags
+; CHECK: [[COPY0:%[0-9]+]]:_(s32) = COPY $s0
+; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY $s1
+; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY $s2
+; CHECK: [[COPY3:%[0-9]+]]:_(s32) = COPY $s3
+; CHECK: [[CMP:%[0-9]+]]:_(s1) = nsz G_FCMP floatpred(oeq), [[COPY0]](s32), [[COPY1]]
+; CHECK: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[CMP]](s1), [[COPY2]], [[COPY3]]
+define float @test_select_cmp_flags(float %cmp0, float %cmp1, float %lhs, float %rhs) {
+ %tst = fcmp nsz oeq float %cmp0, %cmp1
+ %res = select i1 %tst, float %lhs, float %rhs
+ ret float %res
+}
+
; CHECK-LABEL: name: test_select_ptr
; CHECK: [[TST_C:%[0-9]+]]:_(s32) = COPY $w0
; CHECK: [[TST:%[0-9]+]]:_(s1) = G_TRUNC [[TST_C]]
Index: llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -1011,10 +1011,8 @@
ArrayRef<Register> Op1Regs = getOrCreateVRegs(*U.getOperand(2));
uint16_t Flags = 0;
- if (const SelectInst *SI = dyn_cast<SelectInst>(&U)) {
- if (const CmpInst *Cmp = dyn_cast<CmpInst>(SI->getCondition()))
- Flags = MachineInstr::copyFlagsFromInstruction(*Cmp);
- }
+ if (const SelectInst *SI = dyn_cast<SelectInst>(&U))
+ Flags = MachineInstr::copyFlagsFromInstruction(*SI);
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: D80209.264885.patch
Type: text/x-patch
Size: 2349 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200519/aae58d6a/attachment-0001.bin>
More information about the llvm-commits
mailing list