[all-commits] [llvm/llvm-project] abfeda: [LSR] Consider post-inc form when creating extends...

Florian Hahn via All-commits all-commits at lists.llvm.org
Sat Jun 17 02:02:21 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: abfeda5af329b5889db709ff74506e20e0b569e9
      https://github.com/llvm/llvm-project/commit/abfeda5af329b5889db709ff74506e20e0b569e9
  Author: Florian Hahn <flo at fhahn.com>
  Date:   2023-06-17 (Sat, 17 Jun 2023)

  Changed paths:
    M llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
    M llvm/test/Transforms/LoopStrengthReduce/X86/postinc-iv-used-by-urem-and-udiv.ll

  Log Message:
  -----------
  [LSR] Consider post-inc form when creating extends/truncates.

GenerateTruncates at the moment creates extends/truncates for post-inc
uses of normalized expressions. For example, if an add rec of the form
{1,+,-1} is used outside the loop, the normalized form will use {1,+,-1}
instead of {0,+,-1}. When naively sign-extending the normalized
expression, it will get extended incorrectly to {1,+,-1} for the wider
type, if the backedge-taken count of the loop is 1.

To address this, the patch updates GenerateTruncates to check if the
LSRUse contains any fixups with PostIncLoops. If that's the case, first
de-normalize the expression, then perform the extend/truncate, then
normalize again.

There may be other places where similar checks are needed and the helper
can be generalized for those cases. I'd not be surprised if other subtle
mis-compiles are caused by this.

Fixes #38847.
Fixes #58039.
Fixes #62852.

Reviewed By: nikic

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




More information about the All-commits mailing list