aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorAndreas Jonson <andjo403@hotmail.com>2025-08-23 09:09:01 +0200
committerGitHub <noreply@github.com>2025-08-23 09:09:01 +0200
commited742f88eb57ddae1cc7954b571b3534cb07889b (patch)
tree8379ede0950d6d7e6c73f35b3117f202c2ad9666 /llvm/lib/Transforms/Utils/SimplifyCFG.cpp
parent46762421c30a361c439ad5930f1fd026601db7f5 (diff)
downloadllvm-ed742f88eb57ddae1cc7954b571b3534cb07889b.zip
llvm-ed742f88eb57ddae1cc7954b571b3534cb07889b.tar.gz
llvm-ed742f88eb57ddae1cc7954b571b3534cb07889b.tar.bz2
[SimplifyCFG] Handle that first matched eq cond in if chain can be Extra condition. (#154007)
Proof: https://alive2.llvm.org/ce/z/TozSD6
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 055e8ca..48a9954 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -568,9 +568,20 @@ struct ConstantComparesGatherer {
/// If the elements in Vals matches the comparisons
bool IsEq = false;
+ // Used to check if the first matched CompValue shall be the Extra check.
+ bool IgnoreFirstMatch = false;
+ bool MultipleMatches = false;
+
/// Construct and compute the result for the comparison instruction Cond
ConstantComparesGatherer(Instruction *Cond, const DataLayout &DL) : DL(DL) {
gather(Cond);
+ if (CompValue || !MultipleMatches)
+ return;
+ Extra = nullptr;
+ Vals.clear();
+ UsedICmps = 0;
+ IgnoreFirstMatch = true;
+ gather(Cond);
}
ConstantComparesGatherer(const ConstantComparesGatherer &) = delete;
@@ -581,10 +592,16 @@ private:
/// Try to set the current value used for the comparison, it succeeds only if
/// it wasn't set before or if the new value is the same as the old one
bool setValueOnce(Value *NewVal) {
- if (CompValue && CompValue != NewVal)
+ if (IgnoreFirstMatch) {
+ IgnoreFirstMatch = false;
return false;
+ }
+ if (CompValue && CompValue != NewVal) {
+ MultipleMatches = true;
+ return false;
+ }
CompValue = NewVal;
- return (CompValue != nullptr);
+ return true;
}
/// Try to match Instruction "I" as a comparison against a constant and