[PATCH] D158181: [SCEVExpander] Fix incorrect reuse of more poisonous instructions (PR63763)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 17 06:27:27 PDT 2023


nikic created this revision.
nikic added reviewers: fhahn, reames, efriedma.
Herald added subscribers: StephenFan, pengfei, dmgreen, javed.absar, zzheng, hiraditya, qcolombet.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

SCEVExpander tries to reuse existing instruction with the same SCEV expression. However, doing this replacement blindly is not safe, because the instruction might be more poisonous.

What we were already doing is to drop poison-generating flags on the reused instruction. But this is not the only way that more poison can be introduced. The poison-generating flag might not be directly on the reused instruction, or the poison contribution might come from something like `0 * %var`, which folds to `0` but can still introduce poison.

This patch fixes the issue in a principled way, by determining which values can contribute poison to the SCEV expression, and then checking whether any additional values can contribute poison to the instruction being reused. Poison-generating flags are dropped if doing that enables reuse.

This is a pretty big hammer and does cause some regressions in tests, but less than I would have expected. I wasn't able to come up with a less intrusive fix that still satisfies the correctness requirements.

Fixes https://github.com/llvm/llvm-project/issues/63763.


https://reviews.llvm.org/D158181

Files:
  llvm/include/llvm/Analysis/ScalarEvolution.h
  llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
  llvm/test/CodeGen/Thumb2/mve-blockplacement.ll
  llvm/test/CodeGen/X86/AMX/amx-greedy-ra-spill-shape.ll
  llvm/test/Transforms/IndVarSimplify/pr63763.ll
  llvm/test/Transforms/LoopUnroll/runtime-exit-phi-scev-invalidation.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158181.551111.patch
Type: text/x-patch
Size: 11414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230817/964d435b/attachment.bin>


More information about the llvm-commits mailing list