From f2856a5a16af9e4068f7f877cd580e5447d35e2b Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Wed, 8 Mar 2017 18:49:54 +0000 Subject: [PATCH] GlobalISel: correctly handle trivial fcmp predicates. It makes sense to only do them once in IRTranslator rather than making everyone deal with them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297304 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/GlobalISel/IRTranslator.cpp | 5 ++++- test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/GlobalISel/IRTranslator.cpp b/lib/CodeGen/GlobalISel/IRTranslator.cpp index 488869f642fb..4d1ac680a45e 100644 --- a/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -193,9 +193,12 @@ bool IRTranslator::translateCompare(const User &U, CmpInst::Predicate Pred = CI ? CI->getPredicate() : static_cast( cast(U).getPredicate()); - if (CmpInst::isIntPredicate(Pred)) MIRBuilder.buildICmp(Pred, Res, Op0, Op1); + else if (Pred == CmpInst::FCMP_FALSE) + MIRBuilder.buildConstant(Res, 0); + else if (Pred == CmpInst::FCMP_TRUE) + MIRBuilder.buildConstant(Res, 1); else MIRBuilder.buildFCmp(Pred, Res, Op0, Op1); diff --git a/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll b/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll index 1bbda24f4446..c0cbf69a2e64 100644 --- a/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll +++ b/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll @@ -1056,6 +1056,17 @@ define void @float_comparison(float* %a.addr, float* %b.addr, i1* %bool.addr) { ret void } +; CHECK-LABEL: name: trivial_float_comparison +; CHECK: [[R1:%[0-9]+]](s1) = G_CONSTANT i1 false +; CHECK: [[R2:%[0-9]+]](s1) = G_CONSTANT i1 true +; CHECK: G_ADD [[R1]], [[R2]] +define i1 @trivial_float_comparison(double %a, double %b) { + %r1 = fcmp false double %a, %b + %r2 = fcmp true double %a, %b + %sum = add i1 %r1, %r2 + ret i1 %sum +} + @var = global i32 0 define i32* @test_global() {