From 2ccfbc8b71aa094476cf6a746d6dfd9a2b2a734c Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 31 Mar 2011 10:11:58 +0000 Subject: [PATCH] InstCombine: fold fcmp (fpext x), (fpext y) -> fcmp x, y. llvm-svn: 128624 --- .../Transforms/InstCombine/InstCombineCompares.cpp | 7 +++++++ llvm/test/Transforms/InstCombine/fcmp.ll | 11 +++++++++++ 2 files changed, 18 insertions(+) create mode 100644 llvm/test/Transforms/InstCombine/fcmp.ll diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 8787e2ae0e02..698b715fd8b9 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2813,5 +2813,12 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { } } + // fcmp (fpext x), (fpext y) -> fcmp x, y + if (FPExtInst *LHSExt = dyn_cast(Op0)) + if (FPExtInst *RHSExt = dyn_cast(Op1)) + if (LHSExt->getSrcTy() == RHSExt->getSrcTy()) + return new FCmpInst(I.getPredicate(), LHSExt->getOperand(0), + RHSExt->getOperand(0)); + return Changed ? &I : 0; } diff --git a/llvm/test/Transforms/InstCombine/fcmp.ll b/llvm/test/Transforms/InstCombine/fcmp.ll new file mode 100644 index 000000000000..bef4855a0ed9 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/fcmp.ll @@ -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 +} +