diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2019-10-28 08:56:23 -0400 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2019-10-28 08:58:28 -0400 |
| commit | f2e93d10fe0c7a845254d35f59f47d439e9ff89b (patch) | |
| tree | f2c59a2661e4d857641487bb34f3d0e69d38f30f /llvm/lib/Transforms/Scalar | |
| parent | ee50590e1684c197bc4336984795e48bf53c7a4e (diff) | |
| download | bcm5719-llvm-f2e93d10fe0c7a845254d35f59f47d439e9ff89b.tar.gz bcm5719-llvm-f2e93d10fe0c7a845254d35f59f47d439e9ff89b.zip | |
[CVP] prevent propagating poison when substituting edge values into a phi (PR43802)
This phi simplification transform was added with:
D45448
However as shown in PR43802:
https://bugs.llvm.org/show_bug.cgi?id=43802
...we must be careful not to propagate poison when we do the substitution.
There might be some more complicated analysis possible to retain the overflow flag,
but it should always be safe and easy to drop flags (we have similar behavior in
instcombine and other passes).
Differential Revision: https://reviews.llvm.org/D69442
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index 2ef85268df4..8c4402b1d04 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -194,7 +194,14 @@ static bool simplifyCommonValuePhi(PHINode *P, LazyValueInfo *LVI, } // All constant incoming values map to the same variable along the incoming - // edges of the phi. The phi is unnecessary. + // edges of the phi. The phi is unnecessary. However, we must drop all + // poison-generating flags to ensure that no poison is propagated to the phi + // location by performing this substitution. + // Warning: If the underlying analysis changes, this may not be enough to + // guarantee that poison is not propagated. + // TODO: We may be able to re-infer flags by re-analyzing the instruction. + if (auto *CommonInst = dyn_cast<Instruction>(CommonValue)) + CommonInst->dropPoisonGeneratingFlags(); P->replaceAllUsesWith(CommonValue); P->eraseFromParent(); ++NumPhiCommon; |

