aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-07-25 03:39:21 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-07-25 03:39:21 +0000
commit126de5d4b45d9fa2c55eaba761103cccd3113468 (patch)
tree014bdaf93764ef02bfe542f25f0040a76f320bea /llvm/lib/Analysis/InstructionSimplify.cpp
parentaedcbf898b7136b3aa09f236240eb5f1f05e4b78 (diff)
downloadllvm-126de5d4b45d9fa2c55eaba761103cccd3113468.zip
llvm-126de5d4b45d9fa2c55eaba761103cccd3113468.tar.gz
llvm-126de5d4b45d9fa2c55eaba761103cccd3113468.tar.bz2
[InstSimplify] Fold trunc([zs]ext(%V)) -> %V
Truncates can completely cancel out a zext or sext instruction. llvm-svn: 276604
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index c7e1724..981fb97 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -3790,9 +3790,15 @@ static Value *SimplifyPHINode(PHINode *PN, const Query &Q) {
}
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;
}