-
-
Save nikic/531267d972ce71edf3896e25bc50456a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit c92757dc7630597e608c83238f79b4983ea43553 | |
Author: Nikita Popov <nikita.ppv@gmail.com> | |
Date: Tue Oct 19 21:05:09 2021 +0200 | |
ephemeral | |
diff --git a/llvm/lib/Analysis/CodeMetrics.cpp b/llvm/lib/Analysis/CodeMetrics.cpp | |
index 8c8e2ee6627f..27c52506352f 100644 | |
--- a/llvm/lib/Analysis/CodeMetrics.cpp | |
+++ b/llvm/lib/Analysis/CodeMetrics.cpp | |
@@ -34,8 +34,9 @@ appendSpeculatableOperands(const Value *V, | |
for (const Value *Operand : U->operands()) | |
if (Visited.insert(Operand).second) | |
- if (isSafeToSpeculativelyExecute(Operand)) | |
- Worklist.push_back(Operand); | |
+ if (const auto *I = dyn_cast<Instruction>(Operand)) | |
+ if (!I->mayHaveSideEffects() && !I->isTerminator()) | |
+ Worklist.push_back(I); | |
} | |
static void completeEphemeralValues(SmallPtrSetImpl<const Value *> &Visited, | |
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp | |
index bf1989c58c20..8991582a7a25 100644 | |
--- a/llvm/lib/Analysis/ValueTracking.cpp | |
+++ b/llvm/lib/Analysis/ValueTracking.cpp | |
@@ -494,7 +494,9 @@ static bool isEphemeralValueOf(const Instruction *I, const Value *E) { | |
if (V == E) | |
return true; | |
- if (V == I || isSafeToSpeculativelyExecute(V)) { | |
+ if (V == I || (isa<Instruction>(V) && | |
+ !cast<Instruction>(V)->mayHaveSideEffects() && | |
+ !cast<Instruction>(V)->isTerminator())) { | |
EphValues.insert(V); | |
if (const User *U = dyn_cast<User>(V)) | |
append_range(WorkSet, U->operands()); | |
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
index 920df4e9d742..84bf364d6d24 100644 | |
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
@@ -2577,11 +2577,11 @@ static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) { | |
int Size = 0; | |
SmallPtrSet<const Value *, 32> EphValues; | |
- auto IsEphemeral = [&](const Value *V) { | |
- if (isa<AssumeInst>(V)) | |
+ auto IsEphemeral = [&](const Instruction *I) { | |
+ if (isa<AssumeInst>(I)) | |
return true; | |
- return isSafeToSpeculativelyExecute(V) && | |
- all_of(V->users(), | |
+ return !I->mayHaveSideEffects() && !I->isTerminator() && | |
+ all_of(I->users(), | |
[&](const User *U) { return EphValues.count(U); }); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment