diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2017-03-20 21:59:24 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2017-03-20 21:59:24 +0000 |
commit | 6b00d409003853e8bdaa8c25c4e1e436b1ed2f28 (patch) | |
tree | dbb987321dfc8fd59b80d5411c2569739c7f0220 /llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | |
parent | 4340d64f916c95dcfec1159ebab3d9d1b278a8d8 (diff) | |
download | bcm5719-llvm-6b00d409003853e8bdaa8c25c4e1e436b1ed2f28.tar.gz bcm5719-llvm-6b00d409003853e8bdaa8c25c4e1e436b1ed2f28.zip |
InstCombine: Check source value precision when reducing cast intrinsic
Missed this check when porting from the libcall version.
llvm-svn: 298312
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 98335ba4542..e08c301ccdd 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1442,10 +1442,22 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &CI) { case Intrinsic::round: case Intrinsic::nearbyint: case Intrinsic::trunc: { + Value *Src = II->getArgOperand(0); + if (!Src->hasOneUse()) + break; + + // Except for fabs, this transformation requires the input of the unary FP + // operation to be itself an fpext from the type to which we're + // truncating. + if (II->getIntrinsicID() != Intrinsic::fabs) { + FPExtInst *FPExtSrc = dyn_cast<FPExtInst>(Src); + if (!FPExtSrc || FPExtSrc->getOperand(0)->getType() != CI.getType()) + break; + } + // Do unary FP operation on smaller type. // (fptrunc (fabs x)) -> (fabs (fptrunc x)) - Value *InnerTrunc = Builder->CreateFPTrunc(II->getArgOperand(0), - CI.getType()); + Value *InnerTrunc = Builder->CreateFPTrunc(Src, CI.getType()); Type *IntrinsicType[] = { CI.getType() }; Function *Overload = Intrinsic::getDeclaration( CI.getModule(), II->getIntrinsicID(), IntrinsicType); |