[all-commits] [llvm/llvm-project] f39978: [SCEV] Correctly propagate nowrap flags across sco...

Philip Reames via All-commits all-commits at lists.llvm.org
Sun Oct 3 15:23:25 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f39978b84f1d3a1da6c32db48f64c8daae64b3ad
      https://github.com/llvm/llvm-project/commit/f39978b84f1d3a1da6c32db48f64c8daae64b3ad
  Author: Philip Reames <listmail at philipreames.com>
  Date:   2021-10-03 (Sun, 03 Oct 2021)

  Changed paths:
    M llvm/lib/Analysis/ScalarEvolution.cpp
    M llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll
    M llvm/test/Analysis/ScalarEvolution/incorrect-exit-count.ll
    M llvm/test/Analysis/ScalarEvolution/no-wrap-add-exprs.ll
    M llvm/test/Analysis/ScalarEvolution/nsw-offset-assume.ll
    M llvm/test/Analysis/ScalarEvolution/nsw-offset.ll
    M llvm/test/CodeGen/PowerPC/lsr-profitable-chain.ll
    M llvm/test/Transforms/LoopIdiom/basic.ll

  Log Message:
  -----------
  [SCEV] Correctly propagate nowrap flags across scopes when folding invariant add through addrec

This fixes a violation of the wrap flag rules introduced in c4048d8f. This is an alternate fix to D106852.

The basic problem being fixed is that we infer a set of flags which is valid at some inner scope S1 (usually by correctly propagating them from IR), and then (incorrectly) extend them to a SCEV in scope S2 where S1 != S2. This is not in general safe per the wrap flags semantics recently defined.

In this patch, I include a simple inference step to handle the case where we can prove that S2 is the preheader of the loop S1, and that entry into S2 implies execution of S1. See the code for a more detailed explanation.

One worry I have with this patch is that I might be over-fitting what shows up in tests - and thus hiding negative impact we'd see in the real world. My best defense is that the rule used here very closely follows the one used to propagate the flags from IR to the inner add to start with, and thus if one is reasonable, so probably is the other. Curious what others think about that piece.

The test diffs are roughly as expected. Mostly analysis only, with two transform changes. Oddly, the result looks better in the loop-idiom test, and I don't understand the PPC output enough to have tell. Nothing terrible looking though. (For context, without the scope inference peephole, the test delta includes a couple of vectorization tests. Again, not super concerning, but slightly more so.)

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




More information about the All-commits mailing list