[PATCH] D95286: [LSR] Drop potentially invalid nowrap flags when switching to post-inc IV (PR46943)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 23 05:52:31 PST 2021


nikic created this revision.
nikic added reviewers: fhahn, reames, mkazantsev.
Herald added subscribers: dmgreen, javed.absar.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When LSR converts a branch on pre-inc IV into a branch on post-inc IV, the nowrap flags on the addition may no longer be valid. Previously, a poison result of the addition might have been ignored, in which case the program was well defined. After branching on the post-inc IV, we might be branching on poison, which is undefined behavior.

Fix this by discarding nowrap flags which are not present on the SCEV expression. Nowrap flags on the SCEV expression are proven by SCEV to always hold, independently of how the expression will be used. This is essentially the same fix we applied to IndVars LFTR, which also performs this kind of pre-inc to post-inc conversion.

I believe a similar problem can also exist for getelementptr inbounds, but I was not able to come up with a problematic test case. The inbounds case would have to be addressed in a differently anyway (as SCEV does not track this property).

Fixes https://bugs.llvm.org/show_bug.cgi?id=46943.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95286

Files:
  lib/Transforms/Utils/ScalarEvolutionExpander.cpp
  test/CodeGen/Thumb2/LowOverheadLoops/fast-fp-loops.ll
  test/CodeGen/Thumb2/LowOverheadLoops/mve-float-loops.ll
  test/CodeGen/Thumb2/LowOverheadLoops/mve-tail-data-types.ll
  test/Transforms/LoopStrengthReduce/X86/pr46943.ll
  test/Transforms/LoopStrengthReduce/X86/sibling-loops.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95286.318751.patch
Type: text/x-patch
Size: 33195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210123/dbc23ec7/attachment-0001.bin>


More information about the llvm-commits mailing list