[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 22:29:53 PDT 2023


vedant-amd added inline comments.


================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:7894
+          int64_t AddOperand = AddOperandCI->getSExtValue();
+          const SCEV *AddConstant = getConstant(TruncTy, AddOperand >> AShrAmt);
+
----------------
vedant-amd wrote:
> 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]);
> ```
> I guess the reason AddOperandCI has to be a constant is that this shift needs to constant-fold?

This can be implemented for non-constants as well, maybe in a future patch. But, it involves coming up with complex SCEV expression involving div.


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