InstCombine: fold fcmp (fpext x), (fpext y) -> fcmp x, y.
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 31 Mar 2011 10:11:58 +0000 (10:11 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 31 Mar 2011 10:11:58 +0000 (10:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128624 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/fcmp.ll [new file with mode: 0644]

index 8787e2ae0e02e19a7639aff5e43c7e134419f1c8..698b715fd8b98cd4f28280149421d1b4c5744c8c 100644 (file)
@@ -2813,5 +2813,12 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
       }
   }
 
+  // fcmp (fpext x), (fpext y) -> fcmp x, y
+  if (FPExtInst *LHSExt = dyn_cast<FPExtInst>(Op0))
+    if (FPExtInst *RHSExt = dyn_cast<FPExtInst>(Op1))
+      if (LHSExt->getSrcTy() == RHSExt->getSrcTy())
+        return new FCmpInst(I.getPredicate(), LHSExt->getOperand(0),
+                            RHSExt->getOperand(0));
+
   return Changed ? &I : 0;
 }
diff --git a/test/Transforms/InstCombine/fcmp.ll b/test/Transforms/InstCombine/fcmp.ll
new file mode 100644 (file)
index 0000000..bef4855
--- /dev/null
@@ -0,0 +1,11 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+define i1 @test1(float %x, float %y) nounwind {
+  %ext1 = fpext float %x to double
+  %ext2 = fpext float %y to double
+  %cmp = fcmp ogt double %ext1, %ext2
+  ret i1 %cmp
+; CHECK: @test1
+; CHECK-NEXT: fcmp ogt float %x, %y
+}
+