[llvm] a344653 - [GlobalISel] Fix IRTranslator for constexpr fcmp
Konstantin Schwarz via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 9 23:49:27 PST 2021
Author: Konstantin Schwarz
Date: 2021-12-10T08:49:12+01:00
New Revision: a34465372507a654ff4ec8c1f7faabda4c5d9ab9
URL: https://github.com/llvm/llvm-project/commit/a34465372507a654ff4ec8c1f7faabda4c5d9ab9
DIFF: https://github.com/llvm/llvm-project/commit/a34465372507a654ff4ec8c1f7faabda4c5d9ab9.diff
LOG: [GlobalISel] Fix IRTranslator for constexpr fcmp
The existing code assumed fcmp to always be an Instruction, but it can also be a ConstExpr.
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D115450
Added:
Modified:
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-constantexpr.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index b202c9de4ab7e..6d415c9c7f90c 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -338,9 +338,10 @@ bool IRTranslator::translateCompare(const User &U,
MIRBuilder.buildCopy(
Res, getOrCreateVReg(*Constant::getAllOnesValue(U.getType())));
else {
- assert(CI && "Instruction should be CmpInst");
- MIRBuilder.buildFCmp(Pred, Res, Op0, Op1,
- MachineInstr::copyFlagsFromInstruction(*CI));
+ uint16_t Flags = 0;
+ if (CI)
+ Flags = MachineInstr::copyFlagsFromInstruction(*CI);
+ MIRBuilder.buildFCmp(Pred, Res, Op0, Op1, Flags);
}
return true;
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-constantexpr.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-constantexpr.ll
index fd3d450356717..0c15a9ed2675c 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-constantexpr.ll
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-constantexpr.ll
@@ -59,3 +59,26 @@ define amdgpu_kernel void @constantexpr_select_1() {
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
}
+
+ at a = external global [2 x i32], align 4
+
+define i32 @test_fcmp_constexpr() {
+ ; CHECK-LABEL: name: test_fcmp_constexpr
+ ; CHECK: bb.1.entry:
+ ; CHECK: liveins: $sgpr30_sgpr31
+ ; CHECK: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
+ ; CHECK: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @a
+ ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 4
+ ; CHECK: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[GV]], [[C]](s64)
+ ; CHECK: [[GV1:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var
+ ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[PTR_ADD]](p0), [[GV1]]
+ ; CHECK: [[UITOFP:%[0-9]+]]:_(s32) = G_UITOFP [[ICMP]](s1)
+ ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_FCONSTANT float 0.000000e+00
+ ; CHECK: [[FCMP:%[0-9]+]]:_(s1) = G_FCMP floatpred(oeq), [[UITOFP]](s32), [[C1]]
+ ; CHECK: [[ZEXT:%[0-9]+]]:_(s32) = G_ZEXT [[FCMP]](s1)
+ ; CHECK: $vgpr0 = COPY [[ZEXT]](s32)
+ ; CHECK: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
+ ; CHECK: S_SETPC_B64_return [[COPY1]], implicit $vgpr0
+entry:
+ ret i32 zext (i1 fcmp oeq (float uitofp (i1 icmp eq (i32* getelementptr inbounds ([2 x i32], [2 x i32]* @a, i64 0, i64 1), i32* @var) to float), float 0.000000e+00) to i32)
+}
More information about the llvm-commits
mailing list