[PATCH] D152278: [SCEV] Compute SCEV for ashr(add(shl(x, n), c), m) instr triplet
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 3 08:43:59 PDT 2023
efriedma 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
----------------
vedant-amd wrote:
> 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 ?
I suspect the updated code isn't right... can you add an example with a larger operand to the add? The add needs to happen before the sign-extend, but in this specific example, that doesn't matter because the two expressions are equivalent.
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