Skip to content

Commit b108c11

Browse files
committed
[SCEV] Move SCEVPoisonCollector outside function (NFC)
To allow reusing it. Also switch it to store SCEVUnknown rather than SCEV, as only these can produce poison.
1 parent 8f18cf7 commit b108c11

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,36 +4108,38 @@ static bool scevUnconditionallyPropagatesPoisonFromOperands(SCEVTypes Kind) {
41084108
llvm_unreachable("Unknown SCEV kind!");
41094109
}
41104110

4111-
/// Return true if V is poison given that AssumedPoison is already poison.
4112-
static bool impliesPoison(const SCEV *AssumedPoison, const SCEV *S) {
4113-
// The only way poison may be introduced in a SCEV expression is from a
4114-
// poison SCEVUnknown (ConstantExprs are also represented as SCEVUnknown,
4115-
// not SCEVConstant). Notably, nowrap flags in SCEV nodes can *not*
4116-
// introduce poison -- they encode guaranteed, non-speculated knowledge.
4117-
//
4118-
// Additionally, all SCEV nodes propagate poison from inputs to outputs,
4119-
// with the notable exception of umin_seq, where only poison from the first
4120-
// operand is (unconditionally) propagated.
4121-
struct SCEVPoisonCollector {
4122-
bool LookThroughMaybePoisonBlocking;
4123-
SmallPtrSet<const SCEV *, 4> MaybePoison;
4124-
SCEVPoisonCollector(bool LookThroughMaybePoisonBlocking)
4125-
: LookThroughMaybePoisonBlocking(LookThroughMaybePoisonBlocking) {}
4126-
4127-
bool follow(const SCEV *S) {
4128-
if (!LookThroughMaybePoisonBlocking &&
4129-
!scevUnconditionallyPropagatesPoisonFromOperands(S->getSCEVType()))
4130-
return false;
4111+
namespace {
4112+
// The only way poison may be introduced in a SCEV expression is from a
4113+
// poison SCEVUnknown (ConstantExprs are also represented as SCEVUnknown,
4114+
// not SCEVConstant). Notably, nowrap flags in SCEV nodes can *not*
4115+
// introduce poison -- they encode guaranteed, non-speculated knowledge.
4116+
//
4117+
// Additionally, all SCEV nodes propagate poison from inputs to outputs,
4118+
// with the notable exception of umin_seq, where only poison from the first
4119+
// operand is (unconditionally) propagated.
4120+
struct SCEVPoisonCollector {
4121+
bool LookThroughMaybePoisonBlocking;
4122+
SmallPtrSet<const SCEVUnknown *, 4> MaybePoison;
4123+
SCEVPoisonCollector(bool LookThroughMaybePoisonBlocking)
4124+
: LookThroughMaybePoisonBlocking(LookThroughMaybePoisonBlocking) {}
4125+
4126+
bool follow(const SCEV *S) {
4127+
if (!LookThroughMaybePoisonBlocking &&
4128+
!scevUnconditionallyPropagatesPoisonFromOperands(S->getSCEVType()))
4129+
return false;
41314130

4132-
if (auto *SU = dyn_cast<SCEVUnknown>(S)) {
4133-
if (!isGuaranteedNotToBePoison(SU->getValue()))
4134-
MaybePoison.insert(S);
4135-
}
4136-
return true;
4131+
if (auto *SU = dyn_cast<SCEVUnknown>(S)) {
4132+
if (!isGuaranteedNotToBePoison(SU->getValue()))
4133+
MaybePoison.insert(SU);
41374134
}
4138-
bool isDone() const { return false; }
4139-
};
4135+
return true;
4136+
}
4137+
bool isDone() const { return false; }
4138+
};
4139+
} // namespace
41404140

4141+
/// Return true if V is poison given that AssumedPoison is already poison.
4142+
static bool impliesPoison(const SCEV *AssumedPoison, const SCEV *S) {
41414143
// First collect all SCEVs that might result in AssumedPoison to be poison.
41424144
// We need to look through potentially poison-blocking operations here,
41434145
// because we want to find all SCEVs that *might* result in poison, not only
@@ -4158,8 +4160,9 @@ static bool impliesPoison(const SCEV *AssumedPoison, const SCEV *S) {
41584160

41594161
// Make sure that no matter which SCEV in PC1.MaybePoison is actually poison,
41604162
// it will also make S poison by being part of PC2.MaybePoison.
4161-
return all_of(PC1.MaybePoison,
4162-
[&](const SCEV *S) { return PC2.MaybePoison.contains(S); });
4163+
return all_of(PC1.MaybePoison, [&](const SCEVUnknown *S) {
4164+
return PC2.MaybePoison.contains(S);
4165+
});
41634166
}
41644167

41654168
const SCEV *

0 commit comments

Comments
 (0)