Skip to content

Commit dc6876f

Browse files
authored
[ValueTracking] Use isSafeToSpeculativelyExecuteWithVariableReplaced() in more places (#109149)
This replaces some uses of isSafeToSpeculativelyExecute() with isSafeToSpeculativelyExecuteWithVariableReplaced(), in cases where we are guarding against operand changes rather plain speculation. I believe that this is NFC with the current implementation of the function (as it only does something different from loads), but this makes us more defensive against future generalizations.
1 parent 4e37816 commit dc6876f

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,8 @@ ValueLatticeElement LazyValueInfoImpl::getValueAtUse(const Use &U) {
15721572
// This also disallows looking through phi nodes: If the phi node is part
15731573
// of a cycle, we might end up reasoning about values from different cycle
15741574
// iterations (PR60629).
1575-
if (!CurrI->hasOneUse() || !isSafeToSpeculativelyExecute(CurrI))
1575+
if (!CurrI->hasOneUse() ||
1576+
!isSafeToSpeculativelyExecuteWithVariableReplaced(CurrI))
15761577
break;
15771578
CurrU = &*CurrI->use_begin();
15781579
}

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ Instruction *InstCombinerImpl::visitExtractElementInst(ExtractElementInst &EI) {
476476
// it may make the operand poison.
477477
BinaryOperator *BO;
478478
if (match(SrcVec, m_BinOp(BO)) && cheapToScalarize(SrcVec, Index) &&
479-
(HasKnownValidIndex || isSafeToSpeculativelyExecute(BO))) {
479+
(HasKnownValidIndex ||
480+
isSafeToSpeculativelyExecuteWithVariableReplaced(BO))) {
480481
// extelt (binop X, Y), Index --> binop (extelt X, Index), (extelt Y, Index)
481482
Value *X = BO->getOperand(0), *Y = BO->getOperand(1);
482483
Value *E0 = Builder.CreateExtractElement(X, Index);
@@ -2777,7 +2778,7 @@ Instruction *InstCombinerImpl::simplifyBinOpSplats(ShuffleVectorInst &SVI) {
27772778
return nullptr;
27782779

27792780
auto *BinOp = cast<BinaryOperator>(Op0);
2780-
if (!isSafeToSpeculativelyExecute(BinOp))
2781+
if (!isSafeToSpeculativelyExecuteWithVariableReplaced(BinOp))
27812782
return nullptr;
27822783

27832784
Value *NewBO = Builder.CreateBinOp(BinOp->getOpcode(), X, Y);

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ Instruction *InstCombinerImpl::foldVectorBinop(BinaryOperator &Inst) {
21052105
// It may not be safe to reorder shuffles and things like div, urem, etc.
21062106
// because we may trap when executing those ops on unknown vector elements.
21072107
// See PR20059.
2108-
if (!isSafeToSpeculativelyExecute(&Inst))
2108+
if (!isSafeToSpeculativelyExecuteWithVariableReplaced(&Inst))
21092109
return nullptr;
21102110

21112111
auto createBinOpShuffle = [&](Value *X, Value *Y, ArrayRef<int> M) {

0 commit comments

Comments
 (0)