diff options
| author | Nikita Popov <nikita.ppv@gmail.com> | 2018-11-26 15:36:57 +0000 |
|---|---|---|
| committer | Nikita Popov <nikita.ppv@gmail.com> | 2018-11-26 15:36:57 +0000 |
| commit | f94c8f0d1b96510b851009adf7f741b7313f4c8f (patch) | |
| tree | ed168c92dcba5a9fc58f193b8eeacb3c4f6fafde /llvm/lib/Analysis | |
| parent | a21392bfc7e45073d4b6967f4daaf29011a2c64f (diff) | |
| download | bcm5719-llvm-f94c8f0d1b96510b851009adf7f741b7313f4c8f.tar.gz bcm5719-llvm-f94c8f0d1b96510b851009adf7f741b7313f4c8f.zip | |
[DemandedBits] Add support for funnel shifts
Add support for funnel shifts to the DemandedBits analysis. The
demanded bits of the first two operands can be determined if the
shift amount is constant. The demanded bits of the third operand
(shift amount) can be determined if the bitwidth is a power of two.
This is basically the same functionality as implemented in D54869
and D54478, but for DemandedBits rather than InstCombine.
Differential Revision: https://reviews.llvm.org/D54876
llvm-svn: 347561
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/DemandedBits.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/DemandedBits.cpp b/llvm/lib/Analysis/DemandedBits.cpp index 35af4be485f..6bef77176cb 100644 --- a/llvm/lib/Analysis/DemandedBits.cpp +++ b/llvm/lib/Analysis/DemandedBits.cpp @@ -142,6 +142,27 @@ void DemandedBits::determineLiveOperandBits( std::min(BitWidth, Known.countMaxTrailingZeros()+1)); } break; + case Intrinsic::fshl: + case Intrinsic::fshr: + if (OperandNo == 2) { + // Shift amount is modulo the bitwidth. For powers of two we have + // SA % BW == SA & (BW - 1). + if (isPowerOf2_32(BitWidth)) + AB = BitWidth - 1; + } else if (auto *SA = dyn_cast<ConstantInt>(II->getOperand(2))) { + // TODO: Support vectors. + // Normalize to funnel shift left. APInt shifts of BitWidth are well- + // defined, so no need to special-case zero shifts here. + uint64_t ShiftAmt = SA->getValue().urem(BitWidth); + if (II->getIntrinsicID() == Intrinsic::fshr) + ShiftAmt = BitWidth - ShiftAmt; + + if (OperandNo == 0) + AB = AOut.lshr(ShiftAmt); + else if (OperandNo == 1) + AB = AOut.shl(BitWidth - ShiftAmt); + } + break; } break; case Instruction::Add: |

