[llvm] r276604 - [InstSimplify] Fold trunc([zs]ext(%V)) -> %V
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 24 20:39:21 PDT 2016
Author: majnemer
Date: Sun Jul 24 22:39:21 2016
New Revision: 276604
URL: http://llvm.org/viewvc/llvm-project?rev=276604&view=rev
Log:
[InstSimplify] Fold trunc([zs]ext(%V)) -> %V
Truncates can completely cancel out a zext or sext instruction.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=276604&r1=276603&r2=276604&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Sun Jul 24 22:39:21 2016
@@ -3790,9 +3790,15 @@ static Value *SimplifyPHINode(PHINode *P
}
static Value *SimplifyTruncInst(Value *Op, Type *Ty, const Query &Q, unsigned) {
- if (Constant *C = dyn_cast<Constant>(Op))
+ if (auto *C = dyn_cast<Constant>(Op))
return ConstantFoldCastOperand(Instruction::Trunc, C, Ty, Q.DL);
+ // trunc([zs]ext(x)) -> x if the trunc undoes the work of the [zs]ext.
+ if (auto *CI = dyn_cast<CastInst>(Op))
+ if (isa<ZExtInst>(CI) || isa<SExtInst>(CI))
+ if (CI->getOperand(0)->getType() == Ty)
+ return CI->getOperand(0);
+
return nullptr;
}
More information about the llvm-commits
mailing list