summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-03-18 14:10:11 +0000
committerSanjay Patel <spatel@rotateright.com>2019-03-18 14:10:11 +0000
commit84de8a30a05a6e0b3685dda4f5dfdd973629504b (patch)
treed2d68e7d626dd987343d42e645807da0e712b020 /llvm/lib/Transforms
parentf9ab4f5f4e9011e5aa0ad2d14622fd1a019d8706 (diff)
downloadbcm5719-llvm-84de8a30a05a6e0b3685dda4f5dfdd973629504b.tar.gz
bcm5719-llvm-84de8a30a05a6e0b3685dda4f5dfdd973629504b.zip
[InstCombine] extend rotate-left-by-constant canonicalization to funnel shift
Follow-up to: rL356338 Rotates are a special case of funnel shift where the 2 input operands are the same value, but that does not need to be a restriction for the canonicalization when the shift amount is a constant. llvm-svn: 356369
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index bdc235f247d..938517e64c3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2006,28 +2006,29 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
II->setArgOperand(2, ModuloC);
return II;
}
- // Canonicalize rotate right by constant to rotate left. This is not
- // entirely arbitrary. For historical reasons, the backend may recognize
- // rotate left patterns but miss rotate right patterns.
- if (II->getIntrinsicID() == Intrinsic::fshr && Op0 == Op1) {
- // fshr X, X, C --> fshl X, X, (BitWidth - C)
+ // Canonicalize funnel shift right by constant to funnel shift left. This
+ // is not entirely arbitrary. For historical reasons, the backend may
+ // recognize rotate left patterns but miss rotate right patterns.
+ if (II->getIntrinsicID() == Intrinsic::fshr) {
+ // fshr X, Y, C --> fshl X, Y, (BitWidth - C)
assert(ConstantExpr::getICmp(ICmpInst::ICMP_UGT, WidthC, ShAmtC) ==
ConstantInt::getTrue(CmpInst::makeCmpResultType(Ty)) &&
"Shift amount expected to be modulo bitwidth");
Constant *LeftShiftC = ConstantExpr::getSub(WidthC, ShAmtC);
Module *Mod = II->getModule();
Function *Fshl = Intrinsic::getDeclaration(Mod, Intrinsic::fshl, Ty);
- return CallInst::Create(Fshl, { Op0, Op0, LeftShiftC });
+ return CallInst::Create(Fshl, { Op0, Op1, LeftShiftC });
}
}
+ // TODO: Pull this into the block above. We can handle semi-arbitrary vector
+ // shift amount constants as well as splats.
const APInt *SA;
if (match(II->getArgOperand(2), m_APInt(SA))) {
uint64_t ShiftAmt = SA->urem(BitWidth);
assert(ShiftAmt != 0 && "SimplifyCall should have handled zero shift");
- // Normalize to funnel shift left.
- if (II->getIntrinsicID() == Intrinsic::fshr)
- ShiftAmt = BitWidth - ShiftAmt;
+ assert(II->getIntrinsicID() == Intrinsic::fshl &&
+ "All funnel shifts by simple constants should go left");
// fshl(X, 0, C) -> shl X, C
// fshl(X, undef, C) -> shl X, C
OpenPOWER on IntegriCloud