[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
Tue Jun 6 08:14:35 PDT 2023


vedant-amd created this revision.
Herald added subscribers: javed.absar, hiraditya.
Herald added a project: All.
vedant-amd requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

%x = shl i64 %w, m
%y = add i64 %x, c
%z = ashr i64 %y, n

The above given instruction triplet is seen many times in the generated
LLVM IR, but SCEV model is not able to compute the SCEV value of AShr
instruction in this case.

This patch models the above case when n = m by using
sext(add(trunc(w), c)) as the SCEV expression. It also adds a unittest
to verify that SCEV is able to compute the value.

$ opt sext-add-inreg.ll -passes="print<scalar-evolution>"

Comparing the snippets of the result of SCEV analysis:

- SCEV of ashr before change ----------------------------

%idxprom = ashr exact i64 %sext, 32

  -->  %idxprom U: [-2147483648,2147483648) S: [-2147483648,2147483648)
  Exits: 8                LoopDispositions: { %for.body: Variant }

- SCEV of ashr after change ---------------------------

%idxprom = ashr exact i64 %sext, 32

  -->  {0,+,1}<nuw><nsw><%for.body> U: [0,9) S: [0,9)
  Exits: 8                LoopDispositions: { %for.body: Computable }

LoopDisposition of the given SCEV was LoopVariant before, after adding
the new way to model the instruction, the LoopDisposition becomes
LoopComputable as it is able to compute the SCEV of the instruction.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152278

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/test/Analysis/ScalarEvolution/sext-add-inreg.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152278.528874.patch
Type: text/x-patch
Size: 8076 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230606/b1a50629/attachment.bin>


More information about the llvm-commits mailing list