[PATCH] D153004: [LSR] Consider post-inc form when creating extends/truncates.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 15 02:18:56 PDT 2023


fhahn created this revision.
fhahn added reviewers: reames, nikic, efriedma, peixin, qcolombet.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
fhahn requested review of this revision.
Herald added a project: LLVM.

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 #62852.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153004

Files:
  llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
  llvm/test/Transforms/LoopStrengthReduce/postinc-iv-used-by-urem.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153004.531657.patch
Type: text/x-patch
Size: 6036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230615/c92ce329/attachment.bin>


More information about the llvm-commits mailing list