[all-commits] [llvm/llvm-project] 8906a0: [SCEVExpander] Drop poison generating flags when r...
Philip Reames via All-commits
all-commits at lists.llvm.org
Mon Nov 29 15:30:00 PST 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 8906a0fe64abf1a9c8641ee51908bba7cbf8ec54
https://github.com/llvm/llvm-project/commit/8906a0fe64abf1a9c8641ee51908bba7cbf8ec54
Author: Philip Reames <listmail at philipreames.com>
Date: 2021-11-29 (Mon, 29 Nov 2021)
Changed paths:
M llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
M llvm/test/CodeGen/PowerPC/common-chain.ll
M llvm/test/Transforms/IRCE/non-loop-invariant-rhs-instr.ll
M llvm/test/Transforms/IndVarSimplify/ashr-expansion.ll
M llvm/test/Transforms/IndVarSimplify/lftr-address-space-pointers.ll
M llvm/test/Transforms/IndVarSimplify/lftr-reuse.ll
M llvm/test/Transforms/IndVarSimplify/pr24783.ll
M llvm/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll
M llvm/test/Transforms/LoopPredication/basic.ll
M llvm/test/Transforms/LoopUnroll/runtime-loop-multiple-exits.ll
M llvm/test/Transforms/PhaseOrdering/loop-rotation-vs-common-code-hoisting.ll
Log Message:
-----------
[SCEVExpander] Drop poison generating flags when reusing instructions
The basic problem we have is that we're trying to reuse an instruction which is mapped to some SCEV. Since we can have multiple such instructions (potentially with different flags), this is analogous to our need to drop flags when performing CSE. A trivial implementation would simply drop flags on any instruction we decided to reuse, and that would be correct.
This patch is almost that trivial patch except that we preserve flags on the reused instruction when existing users would imply UB on overflow already. Adding new users can, at most, refine this program to one which doesn't execute UB which is valid.
In practice, this fixes two conceptual problems with the previous code: 1) a binop could have been canonicalized into a form with different opcode or operands, or 2) the inbounds GEP case which was simply unhandled.
On the test changes, most are pretty straight forward. We loose some flags (in some cases, they'd have been dropped on the next CSE pass anyways). The one that took me the longest to understand was the ashr-expansion test. What's happening there is that we're considering reuse of the mul, previously we disallowed it entirely, now we allow it with no flags. The surrounding diffs are all effects of generating the same mul with a different operand order, and then doing simple DCE.
The loss of the inbounds is unfortunate, but even there, we can recover most of those once we actually treat branch-on-poison as immediate UB.
Differential Revision: https://reviews.llvm.org/D112734
More information about the All-commits
mailing list