From 0db50189dcde3408134e9011052ed8b731ec303a Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 31 Mar 2011 10:12:15 +0000 Subject: [PATCH] InstCombine: fold fcmp pred (fneg x), C -> fcmp swap(pred) x, -C git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128626 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineCompares.cpp | 8 ++++++++ test/Transforms/InstCombine/fcmp.ll | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index 48ce7cffb58..6743885cd42 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2834,6 +2834,14 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { return SelectInst::Create(LHSI->getOperand(0), Op1, Op2); break; } + case Instruction::FSub: { + // fcmp pred (fneg x), C -> fcmp swap(pred) x, -C + Value *Op; + if (match(LHSI, m_FNeg(m_Value(Op)))) + return new FCmpInst(I.getSwappedPredicate(), Op, + ConstantExpr::getFNeg(RHSC)); + break; + } case Instruction::Load: if (GetElementPtrInst *GEP = dyn_cast(LHSI->getOperand(0))) { diff --git a/test/Transforms/InstCombine/fcmp.ll b/test/Transforms/InstCombine/fcmp.ll index 49bd50717dc..f869a18992d 100644 --- a/test/Transforms/InstCombine/fcmp.ll +++ b/test/Transforms/InstCombine/fcmp.ll @@ -32,3 +32,11 @@ define i1 @test4(float %a) nounwind { ; CHECK: @test4 ; CHECK-NEXT: fpext float %a to double } + +define i1 @test5(float %a) nounwind { + %neg = fsub float -0.000000e+00, %a + %cmp = fcmp ogt float %neg, 1.000000e+00 + ret i1 %cmp +; CHECK: @test5 +; CHECK-NEXT: fcmp olt float %a, -1.0 +} -- 2.34.1