[PATCH] D152278: [SCEV] Compute SCEV for ashr(add(shl(x, n), c), m) instr triplet
Vedant Paranjape via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 8 21:40:36 PDT 2023
vedant-amd added inline comments.
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:7893
+ // type, so create a new Constant with type same as TruncTy
+ int64_t AddOperand = AddOperandCI->getSExtValue();
+ const SCEV *AddConstant = getConstant(TruncTy, AddOperand >> AShrAmt);
----------------
efriedma wrote:
> Is there some reason to expect that "c" fits into an int64_t?
Right, I need to add a check like this I guess ?
```
if (CI->getValue().uge(BitWidth))
```
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:7894
+ int64_t AddOperand = AddOperandCI->getSExtValue();
+ const SCEV *AddConstant = getConstant(TruncTy, AddOperand >> AShrAmt);
+
----------------
efriedma wrote:
> I guess the reason AddOperandCI has to be a constant is that this shift needs to constant-fold?
Theoretically, it doesn't have to be a constant. But, I don't see where such a IR will be emitted. I can handle this case in a future patch.
This IR is usually emitted for the following C code. InstCombine does the optimization.
```
int64_t a = 10;
int32_t b = a - 1;
printf("%d", arr[b]);
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152278/new/
https://reviews.llvm.org/D152278
More information about the llvm-commits
mailing list