Skip to content

Commit

Permalink
InstCombine: Check source value precision when reducing cast intrinsic
Browse files Browse the repository at this point in the history
Missed this check when porting from the libcall version.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298312 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
arsenm committed Mar 20, 2017
1 parent b38a51e commit db4ce1d
Show file tree
Hide file tree
Showing 2 changed files with 419 additions and 38 deletions.
16 changes: 14 additions & 2 deletions lib/Transforms/InstCombine/InstCombineCasts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit db4ce1d

Please sign in to comment.