[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 Aug 3 01:03:43 PDT 2023


vedant-amd added inline comments.


================
Comment at: llvm/test/Analysis/ScalarEvolution/sext-add-inreg-unequal.ll:12
+; CHECK-NEXT:    %ashr = ashr exact i64 %shl, 8
+; CHECK-NEXT:    --> (sext i56 (4 * (trunc i64 %a to i56)) to i64) U: [0,-3) S: [-36028797018963968,36028797018963965)
+; CHECK-NEXT:  Determining loop execution counts for: @test00
----------------
efriedma wrote:
> How is this equivalent?  Say %a is zero; the original function returns 1, this SCEV expression returns 0.  (I think maybe the "ashr" of the constant is shifting by 10, instead of shifting by 8?)
Yeah, the SCEV is wrong. I will fix this. This is what is should have been, but it's a bit opposite.

```
= (a*2^10 + 256)/2*8
= a*4 + 1
```
So, we need SCEV like this:

2^(shl_amt - ashr_amt) * a + c >> ashr_amt

I have updated my code, here's the correct SCEV:

(1 + (sext i56 (4 * (trunc i64 %a to i56)) to i64))<nuw><nsw> U: [1,-2) S: [-36028797018963967,36028797018963966)

Does it seem correct ?


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