It's not safe to fold (fptrunc (sqrt (fpext x))) to (sqrtf x) if there is another...
authorEvan Cheng <evan.cheng@apple.com>
Wed, 13 Jul 2011 19:08:16 +0000 (19:08 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Wed, 13 Jul 2011 19:08:16 +0000 (19:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135058 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 036f0d33678fd14c836dfbbb1abeae641416e9df..82c734e0b829ec0bc01901cb30908767e15605e7 100644 (file)
@@ -1216,7 +1216,8 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &CI) {
   CallInst *Call = dyn_cast<CallInst>(CI.getOperand(0));
   if (Call && Call->getCalledFunction() &&
       Call->getCalledFunction()->getName() == "sqrt" &&
   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() &&
     CastInst *Arg = dyn_cast<CastInst>(Call->getArgOperand(0));
     if (Arg && Arg->getOpcode() == Instruction::FPExt &&
         CI.getType()->isFloatTy() &&
index 69e511bfb3bd48734bf98c7082af785cf6af20c5..6ee7a53ae7e648724af5d84c8c37527fb3f34d90 100644 (file)
@@ -14,8 +14,6 @@ entry:
   ret float %conv1
 }
 
   ret float %conv1
 }
 
-declare double @sqrt(double)
-
 ; PR8096
 define float @test2(float %x) nounwind readnone ssp {
 entry:
 ; PR8096
 define float @test2(float %x) nounwind readnone ssp {
 entry:
@@ -30,3 +28,22 @@ entry:
 ; CHECK: ret float
   ret float %conv1
 }
 ; 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
index 7fed125e1bfe9f5117258f63265b419afa6e3625..dfda6f700dc138f55edf2b8c971a66c189593888 100644 (file)
@@ -338,9 +338,11 @@ static int AssembleInput(const char *ProgName) {
   formatted_raw_ostream FOS(Out->os());
   OwningPtr<MCStreamer> Str;
 
   formatted_raw_ostream FOS(Out->os());
   OwningPtr<MCStreamer> Str;
 
+#if 0
   const TargetLoweringObjectFile &TLOF =
     TM->getTargetLowering()->getObjFileLowering();
   const_cast<TargetLoweringObjectFile&>(TLOF).Initialize(Ctx, *TM);
   const TargetLoweringObjectFile &TLOF =
     TM->getTargetLowering()->getObjFileLowering();
   const_cast<TargetLoweringObjectFile&>(TLOF).Initialize(Ctx, *TM);
+#endif
 
   OwningPtr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
   OwningPtr<MCSubtargetInfo>
 
   OwningPtr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
   OwningPtr<MCSubtargetInfo>