llvm-capstone/llvm
Vedant Paranjape 5a9a02f67b [SCEV] Compute SCEV for ashr(add(shl(x, n), c), m) instr triplet
%x = shl i64 %w, n
%y = add i64 %x, c
%z = ashr i64 %y, m

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 two cases of the above instruction pattern using
the following expression:

=> sext(add(mul(trunc(w), 2^(n-m)), c >> m))

1) when n = m the expression reduces to sext(add(trunc(w), c >> n))
as n-m=0, and multiplying with 2^0 gives the same result.

2) when n > m the expression works as given above.

It also adds several 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.

Differential Revision: https://reviews.llvm.org/D152278
2023-08-25 05:42:08 +00:00
..
benchmarks
bindings [IR] Remove support for and/or constant expressions 2023-08-22 09:29:54 +02:00
cmake
docs [LangRef] document override-stack-alignment module flag 2023-08-24 11:08:26 -07:00
examples
include Revert "[DAGCombiner] Change foldAndOrOfSETCC() to optimize and/or patterns with floating points." 2023-08-24 20:39:04 -07:00
lib [SCEV] Compute SCEV for ashr(add(shl(x, n), c), m) instr triplet 2023-08-25 05:42:08 +00:00
projects
resources
runtimes
test [SCEV] Compute SCEV for ashr(add(shl(x, n), c), m) instr triplet 2023-08-25 05:42:08 +00:00
tools [TableGen] Rename ResourceCycles and StartAtCycle to clarify semantics 2023-08-24 19:21:36 -07:00
unittests [test] Disable the -Wself-move warning that triggers on exactly what is being tested (NFC) 2023-08-25 07:40:42 +08:00
utils [TableGen] Rename ResourceCycles and StartAtCycle to clarify semantics 2023-08-24 19:21:36 -07:00
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt [llvm][CMake] Improve error message for unknown or experimental targets 2023-08-17 13:34:36 +00:00
CODE_OWNERS.TXT
configure
CREDITS.TXT
LICENSE.TXT
llvm.spec.in
README.txt
RELEASE_TESTERS.TXT

The LLVM Compiler Infrastructure
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.