[llvm-commits] [llvm] r113260 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineCasts.cpp test/Transforms/InstCombine/sqrt.ll

Chris Lattner sabre at nondot.org
Tue Sep 7 13:01:38 PDT 2010


Author: lattner
Date: Tue Sep  7 15:01:38 2010
New Revision: 113260

URL: http://llvm.org/viewvc/llvm-project?rev=113260&view=rev
Log:
Fix a serious performance regression introduced by r108687 on linux:
turning (fptrunc (sqrt (fpext x))) -> (sqrtf x)  is great, but we have
to delete the original sqrt as well.  Not doing so causes us to do 
two sqrt's when building with -fmath-errno (the default on linux).


Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
    llvm/trunk/test/Transforms/InstCombine/sqrt.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=113260&r1=113259&r2=113260&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Tue Sep  7 15:01:38 2010
@@ -1139,7 +1139,7 @@
         Arg->getOperand(0)->getType()->isFloatTy()) {
       Function *Callee = Call->getCalledFunction();
       Module *M = CI.getParent()->getParent()->getParent();
-      Constant* SqrtfFunc = M->getOrInsertFunction("sqrtf", 
+      Constant *SqrtfFunc = M->getOrInsertFunction("sqrtf", 
                                                    Callee->getAttributes(),
                                                    Builder->getFloatTy(),
                                                    Builder->getFloatTy(),
@@ -1147,6 +1147,11 @@
       CallInst *ret = CallInst::Create(SqrtfFunc, Arg->getOperand(0),
                                        "sqrtfcall");
       ret->setAttributes(Callee->getAttributes());
+      
+      
+      // Remove the old Call.  With -fmath-errno, it won't get marked readnone.
+      Call->replaceAllUsesWith(UndefValue::get(Call->getType()));
+      EraseInstFromFunction(*Call);
       return ret;
     }
   }

Modified: llvm/trunk/test/Transforms/InstCombine/sqrt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/sqrt.ll?rev=113260&r1=113259&r2=113260&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/sqrt.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/sqrt.ll Tue Sep  7 15:01:38 2010
@@ -1,16 +1,32 @@
 ; RUN: opt -S -instcombine %s | FileCheck %s
 
-define float @foo(float %x) nounwind readnone ssp {
+define float @test1(float %x) nounwind readnone ssp {
 entry:
+; CHECK: @test1
 ; CHECK-NOT: fpext
 ; CHECK-NOT: sqrt(
 ; CHECK: sqrtf(
 ; CHECK-NOT: fptrunc
   %conv = fpext float %x to double                ; <double> [#uses=1]
-  %call = tail call double @sqrt(double %conv) nounwind ; <double> [#uses=1]
+  %call = tail call double @sqrt(double %conv) readnone nounwind ; <double> [#uses=1]
   %conv1 = fptrunc double %call to float          ; <float> [#uses=1]
 ; CHECK: ret float
   ret float %conv1
 }
 
-declare double @sqrt(double) readnone
+declare double @sqrt(double)
+
+; PR8096
+define float @test2(float %x) nounwind readnone ssp {
+entry:
+; CHECK: @test2
+; CHECK-NOT: fpext
+; CHECK-NOT: sqrt(
+; CHECK: sqrtf(
+; CHECK-NOT: fptrunc
+  %conv = fpext float %x to double                ; <double> [#uses=1]
+  %call = tail call double @sqrt(double %conv) nounwind ; <double> [#uses=1]
+  %conv1 = fptrunc double %call to float          ; <float> [#uses=1]
+; CHECK: ret float
+  ret float %conv1
+}





More information about the llvm-commits mailing list