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

Evan Cheng evan.cheng at apple.com
Wed Jul 13 12:08:17 PDT 2011


Author: evancheng
Date: Wed Jul 13 14:08:16 2011
New Revision: 135058

URL: http://llvm.org/viewvc/llvm-project?rev=135058&view=rev
Log:
It's not safe to fold (fptrunc (sqrt (fpext x))) to (sqrtf x) if there is another use of sqrt. rdar://9763193

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

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=135058&r1=135057&r2=135058&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Wed Jul 13 14:08:16 2011
@@ -1216,7 +1216,8 @@
   CallInst *Call = dyn_cast<CallInst>(CI.getOperand(0));
   if (Call && Call->getCalledFunction() &&
       Call->getCalledFunction()->getName() == "sqrt" &&
-      Call->getNumArgOperands() == 1) {
+      Call->getNumArgOperands() == 1 &&
+      Call->hasOneUse()) {
     CastInst *Arg = dyn_cast<CastInst>(Call->getArgOperand(0));
     if (Arg && Arg->getOpcode() == Instruction::FPExt &&
         CI.getType()->isFloatTy() &&

Modified: llvm/trunk/test/Transforms/InstCombine/sqrt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/sqrt.ll?rev=135058&r1=135057&r2=135058&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/sqrt.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/sqrt.ll Wed Jul 13 14:08:16 2011
@@ -14,8 +14,6 @@
   ret float %conv1
 }
 
-declare double @sqrt(double)
-
 ; PR8096
 define float @test2(float %x) nounwind readnone ssp {
 entry:
@@ -30,3 +28,22 @@
 ; CHECK: ret float
   ret float %conv1
 }
+
+; rdar://9763193
+; Can't fold (fptrunc (sqrt (fpext x))) -> (sqrtf x) since there is another
+; use of sqrt result.
+define float @test3(float* %v) nounwind uwtable ssp {
+entry:
+; CHECK: @test3
+; CHECK: sqrt(
+; CHECK-NOT: sqrtf(
+; CHECK: fptrunc
+  %call34 = call double @sqrt(double undef) nounwind readnone
+  %call36 = call i32 (double)* @foo(double %call34) nounwind
+  %conv38 = fptrunc double %call34 to float
+  ret float %conv38
+}
+
+declare i32 @foo(double)
+
+declare double @sqrt(double) readnone

Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=135058&r1=135057&r2=135058&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Wed Jul 13 14:08:16 2011
@@ -338,9 +338,11 @@
   formatted_raw_ostream FOS(Out->os());
   OwningPtr<MCStreamer> Str;
 
+#if 0
   const TargetLoweringObjectFile &TLOF =
     TM->getTargetLowering()->getObjFileLowering();
   const_cast<TargetLoweringObjectFile&>(TLOF).Initialize(Ctx, *TM);
+#endif
 
   OwningPtr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
   OwningPtr<MCSubtargetInfo>





More information about the llvm-commits mailing list