summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-10-14 21:56:40 +0000
committerSanjay Patel <spatel@rotateright.com>2019-10-14 21:56:40 +0000
commit1f40f15d54aac06421448b6de131231d2d78bc75 (patch)
treeda67f8a42ddd2b267bf4de0f8e48196c1e8e5ae1 /llvm/lib
parent9585d8c11a57f1d5038465ab8f90461c701053fb (diff)
downloadbcm5719-llvm-1f40f15d54aac06421448b6de131231d2d78bc75.tar.gz
bcm5719-llvm-1f40f15d54aac06421448b6de131231d2d78bc75.zip
[InstCombine] fold a shifted bool zext to a select
For a constant shift amount, add the following fold. shl (zext (i1 X)), ShAmt --> select (X, 1 << ShAmt, 0) https://rise4fun.com/Alive/IZ9 Fixes PR42257. Based on original patch by @zvi (Zvi Rackover) Differential Revision: https://reviews.llvm.org/D63382 llvm-svn: 374828
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index ca1885a6128..9187c70fb84 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -934,6 +934,12 @@ Instruction *InstCombiner::visitShl(BinaryOperator &I) {
return BinaryOperator::CreateLShr(
ConstantInt::get(Ty, APInt::getSignMask(BitWidth)), X);
+ // shl (zext (i1 X)), C1 --> select (X, 1 << C1, 0)
+ if (match(Op0, m_ZExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) {
+ auto *NewC = ConstantExpr::getShl(ConstantInt::get(Ty, 1), C1);
+ return SelectInst::Create(X, NewC, ConstantInt::getNullValue(Ty));
+ }
+
return nullptr;
}
OpenPOWER on IntegriCloud