summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-11-16 14:40:51 +0000
committerSanjay Patel <spatel@rotateright.com>2017-11-16 14:40:51 +0000
commitb3fa94586f6f466fe3d7b7d2595b97c5efa3f9c2 (patch)
tree0ab34875672d25cdc7b8d4ea479b89ee59831fbf /llvm/lib/Transforms
parent89bca9e56642a1631acfa7a874489a1a989927dc (diff)
downloadbcm5719-llvm-b3fa94586f6f466fe3d7b7d2595b97c5efa3f9c2.tar.gz
bcm5719-llvm-b3fa94586f6f466fe3d7b7d2595b97c5efa3f9c2.zip
[InstCombine] include 'sub' in the list of narrow-able binops
// trunc (binop X, C) --> binop (trunc X, C') // trunc (binop (ext X), Y) --> binop X, (trunc Y) I'm grouping sub with the other binops because that makes the code simpler and the transforms are valid: https://rise4fun.com/Alive/UeF ...so even though we don't expect a sub with constant Op1 or any of the other opcodes with constant Op0 due to canonicalization rules, we might as well handle those situations if non-canonical code somehow reaches this point (it should just make instcombine more efficient in reaching its end goal). This should solve the problem that later manifests in the vectorizers in PR35295: https://bugs.llvm.org/show_bug.cgi?id=35295 llvm-svn: 318404
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index c2fe661c467..178c8eaf250 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -552,8 +552,15 @@ Instruction *InstCombiner::narrowBinOp(TruncInst &Trunc) {
case Instruction::Or:
case Instruction::Xor:
case Instruction::Add:
+ case Instruction::Sub:
case Instruction::Mul: {
Constant *C;
+ if (match(BinOp0, m_Constant(C))) {
+ // trunc (binop C, X) --> binop (trunc C', X)
+ Constant *NarrowC = ConstantExpr::getTrunc(C, DestTy);
+ Value *TruncX = Builder.CreateTrunc(BinOp1, DestTy);
+ return BinaryOperator::Create(BinOp->getOpcode(), NarrowC, TruncX);
+ }
if (match(BinOp1, m_Constant(C))) {
// trunc (binop X, C) --> binop (trunc X, C')
Constant *NarrowC = ConstantExpr::getTrunc(C, DestTy);
@@ -573,16 +580,6 @@ Instruction *InstCombiner::narrowBinOp(TruncInst &Trunc) {
}
break;
}
- case Instruction::Sub: {
- Constant *C;
- if (match(BinOp0, m_Constant(C))) {
- // trunc (binop C, X) --> binop (trunc C', X)
- Constant *NarrowC = ConstantExpr::getTrunc(C, DestTy);
- Value *TruncX = Builder.CreateTrunc(BinOp1, DestTy);
- return BinaryOperator::Create(BinOp->getOpcode(), NarrowC, TruncX);
- }
- break;
- }
default: break;
}
OpenPOWER on IntegriCloud