[all-commits] [llvm/llvm-project] ce1ac1: [SCEV] Don't store AddRec loop when simplifying mu...

Dmitry Makogon via All-commits all-commits at lists.llvm.org
Thu Jun 22 01:49:57 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ce1ac1cf18040486e2d2ec0b962287afc1641fec
      https://github.com/llvm/llvm-project/commit/ce1ac1cf18040486e2d2ec0b962287afc1641fec
  Author: Dmitry Makogon <d.makogon at g.nsu.ru>
  Date:   2023-06-22 (Thu, 22 Jun 2023)

  Changed paths:
    M llvm/lib/Analysis/ScalarEvolution.cpp
    M llvm/test/Analysis/ScalarEvolution/pr62430.ll

  Log Message:
  -----------
  [SCEV] Don't store AddRec loop when simplifying multiplication of AddRecs

When multiplying several AddRecs, we do the following simplification:

{A1,+,A2,+,...,+,An}<L> * {B1,+,B2,+,...,+,Bn}<L> = {x=1 in [ sum y=x..2x
	[ sum z=max(y-x, y-n)..min(x,n) [
		choose(x, 2x)*choose(2x-y, x-z)*A_{y-z}*B_z]]
	],+,...up to x=2n}

This is done iteratively, pair by pair. So if we try to multiply three AddRecs
A1, A2, A3, then we'd try to simplify A1 * A2 to A1' and then try to
simplify A1' * A3 if A1' is also an AddRec.
The transform is only legal if the loops of the two AddRecs are the same.
It is checked in the code, but the loop of one of the AddRecs is stored
in a local variable and doesn't get updated when we simplify a pair to a new AddRec.
In the motivating test the new AddRec A1' was created for a different loop and,
as the loop variable didn't get updated, the check for different loops passed and
the transform worked for two AddRecs from different loops.
So it created a wrong SCEV. And it caused LSR to replace an instruction with another
one that had the same SCEV as the incorrectly computed one.

Differential Revision: https://reviews.llvm.org/D153254




More information about the All-commits mailing list