aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-11-07 14:09:45 +0100
committerGitHub <noreply@github.com>2024-11-07 14:09:45 +0100
commitdd116369f646d023a2e7e5c145a1bed5dcf9a45c (patch)
treecebe64950df0a621080e3b40ad27a0e78a8b169b /llvm/lib/Analysis/InstructionSimplify.cpp
parent4fb953ac348d888541efe515439e0d844cdd7fbf (diff)
downloadllvm-dd116369f646d023a2e7e5c145a1bed5dcf9a45c.zip
llvm-dd116369f646d023a2e7e5c145a1bed5dcf9a45c.tar.gz
llvm-dd116369f646d023a2e7e5c145a1bed5dcf9a45c.tar.bz2
[InstSimplify] Fix incorrect poison propagation when folding phi (#96631)
We can only replace phi(X, undef) with X, if X is known not to be poison. Otherwise, the result may be more poisonous on the undef branch. Fixes https://github.com/llvm/llvm-project/issues/68683.
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 2cb2612..daa468a 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5315,7 +5315,14 @@ static Value *simplifyPHINode(PHINode *PN, ArrayRef<Value *> IncomingValues,
// If we have a PHI node like phi(X, undef, X), where X is defined by some
// instruction, we cannot return X as the result of the PHI node unless it
// dominates the PHI block.
- return valueDominatesPHI(CommonValue, PN, Q.DT) ? CommonValue : nullptr;
+ if (!valueDominatesPHI(CommonValue, PN, Q.DT))
+ return nullptr;
+
+ // Make sure we do not replace an undef value with poison.
+ if (HasUndefInput &&
+ !isGuaranteedNotToBePoison(CommonValue, Q.AC, Q.CxtI, Q.DT))
+ return nullptr;
+ return CommonValue;
}
return CommonValue;