diff options
author | Nikita Popov <npopov@redhat.com> | 2023-10-31 10:20:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-31 10:20:07 +0100 |
commit | 75881dbb0fa5dcfe08518b6fb72621cbf60f45e2 (patch) | |
tree | f9e6befeb18493fc911a0f8ec9288228b0fd43d5 /llvm/lib/Transforms/Scalar/JumpThreading.cpp | |
parent | 33b85867e30e1adc2ff2173039c199b81c10f52b (diff) | |
download | llvm-75881dbb0fa5dcfe08518b6fb72621cbf60f45e2.zip llvm-75881dbb0fa5dcfe08518b6fb72621cbf60f45e2.tar.gz llvm-75881dbb0fa5dcfe08518b6fb72621cbf60f45e2.tar.bz2 |
[JumpThreading] Don't phi translate past loop phi (#70664)
When evaluating comparisons in predecessors, phi operands are translated
into the predecessor. If the translation is across a backedge, this
means that the two operands of the icmp will be from two different loop
iterations, resulting in incorrect simplification.
Fix this by not performing the phi translation for phis in loop headers.
Note: This is not a complete fix. If the
jump-threading-across-loop-headers option is enabled, the LoopHeaders
variable does not get populated. Additional changes will be needed to
fix that case.
Related to https://github.com/llvm/llvm-project/issues/70651.
Diffstat (limited to 'llvm/lib/Transforms/Scalar/JumpThreading.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index f2b9d78..7a8128c 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -761,7 +761,10 @@ bool JumpThreadingPass::computeValueKnownInPredecessorsImpl( PHINode *PN = dyn_cast<PHINode>(CmpLHS); if (!PN) PN = dyn_cast<PHINode>(CmpRHS); - if (PN && PN->getParent() == BB) { + // Do not perform phi translation across a loop header phi, because this + // may result in comparison of values from two different loop iterations. + // FIXME: This check is broken if LoopHeaders is not populated. + if (PN && PN->getParent() == BB && !LoopHeaders.contains(BB)) { const DataLayout &DL = PN->getModule()->getDataLayout(); // We can do this simplification if any comparisons fold to true or false. // See if any do. |