summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2011-07-13 19:08:16 +0000
committerEvan Cheng <evan.cheng@apple.com>2011-07-13 19:08:16 +0000
commitb94674b325143837f6941196f95525dee8482d2c (patch)
tree3c83a68edc83c68284481499ec08f22b1db7dfb9 /llvm
parent9a881019a597d218f838fb1e2b92fba19258a5bd (diff)
downloadbcm5719-llvm-b94674b325143837f6941196f95525dee8482d2c.tar.gz
bcm5719-llvm-b94674b325143837f6941196f95525dee8482d2c.zip
It's not safe to fold (fptrunc (sqrt (fpext x))) to (sqrtf x) if there is another use of sqrt. rdar://9763193
llvm-svn: 135058
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp3
-rw-r--r--llvm/test/Transforms/InstCombine/sqrt.ll21
-rw-r--r--llvm/tools/llvm-mc/llvm-mc.cpp2
3 files changed, 23 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 036f0d33678..82c734e0b82 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -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" &&
- 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() &&
diff --git a/llvm/test/Transforms/InstCombine/sqrt.ll b/llvm/test/Transforms/InstCombine/sqrt.ll
index 69e511bfb3b..6ee7a53ae7e 100644
--- a/llvm/test/Transforms/InstCombine/sqrt.ll
+++ b/llvm/test/Transforms/InstCombine/sqrt.ll
@@ -14,8 +14,6 @@ entry:
ret float %conv1
}
-declare double @sqrt(double)
-
; PR8096
define float @test2(float %x) nounwind readnone ssp {
entry:
@@ -30,3 +28,22 @@ entry:
; 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
diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp
index 7fed125e1bf..dfda6f700dc 100644
--- a/llvm/tools/llvm-mc/llvm-mc.cpp
+++ b/llvm/tools/llvm-mc/llvm-mc.cpp
@@ -338,9 +338,11 @@ static int AssembleInput(const char *ProgName) {
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>
OpenPOWER on IntegriCloud