From 93a635c82c33e331bd4c5f4f44ba1e37a08bd687 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Wed, 13 Jul 2011 19:08:16 +0000 Subject: [PATCH] It's not safe to fold (fptrunc (sqrt (fpext x))) to (sqrtf x) if there is another use of sqrt. rdar://9763193 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135058 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../InstCombine/InstCombineCasts.cpp | 3 ++- test/Transforms/InstCombine/sqrt.ll | 21 +++++++++++++++++-- tools/llvm-mc/llvm-mc.cpp | 2 ++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp index 036f0d33678..82c734e0b82 100644 --- a/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1216,7 +1216,8 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &CI) { CallInst *Call = dyn_cast(CI.getOperand(0)); if (Call && Call->getCalledFunction() && Call->getCalledFunction()->getName() == "sqrt" && - Call->getNumArgOperands() == 1) { + Call->getNumArgOperands() == 1 && + Call->hasOneUse()) { CastInst *Arg = dyn_cast(Call->getArgOperand(0)); if (Arg && Arg->getOpcode() == Instruction::FPExt && CI.getType()->isFloatTy() && diff --git a/test/Transforms/InstCombine/sqrt.ll b/test/Transforms/InstCombine/sqrt.ll index 69e511bfb3b..6ee7a53ae7e 100644 --- a/test/Transforms/InstCombine/sqrt.ll +++ b/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/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 7fed125e1bf..dfda6f700dc 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -338,9 +338,11 @@ static int AssembleInput(const char *ProgName) { formatted_raw_ostream FOS(Out->os()); OwningPtr Str; +#if 0 const TargetLoweringObjectFile &TLOF = TM->getTargetLowering()->getObjFileLowering(); const_cast(TLOF).Initialize(Ctx, *TM); +#endif OwningPtr MCII(TheTarget->createMCInstrInfo()); OwningPtr -- 2.34.1