Skip to content

Commit

Permalink
ValueTracking, InstSimplify: address review
Browse files Browse the repository at this point in the history
  • Loading branch information
artagnon committed Oct 12, 2024
1 parent b2a7446 commit 0e9d014
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 1 addition & 2 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4343,8 +4343,7 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
if (isa<PHINode>(I))
return nullptr;

if (Op->getType()->isVectorTy() &&
(!I->getType()->isVectorTy() || !isLanewiseOperation(I)))
if (Op->getType()->isVectorTy() && !isLanewiseOperation(I))
// For vector types, the simplification must hold per-lane, so forbid
// potentially cross-lane operations like shufflevector.
return nullptr;
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6950,6 +6950,7 @@ bool llvm::onlyUsedByLifetimeMarkersOrDroppableInsts(const Value *V) {
bool llvm::isLanewiseOperation(const Instruction *I) {
if (auto *II = dyn_cast<IntrinsicInst>(I)) {
switch (II->getIntrinsicID()) {
// TODO: expand this list.
case Intrinsic::ctlz:
case Intrinsic::cttz:
case Intrinsic::ctpop:
Expand All @@ -6967,8 +6968,8 @@ bool llvm::isLanewiseOperation(const Instruction *I) {
}
}
auto *Shuffle = dyn_cast<ShuffleVectorInst>(I);
return (!Shuffle || Shuffle->isIdentity() || Shuffle->isSelect()) &&
!isa<CallBase>(I) && !isa<BitCastInst>(I);
return (!Shuffle || Shuffle->isSelect()) &&
!isa<CallBase, BitCastInst, ExtractElementInst>(I);
}

bool llvm::isSafeToSpeculativelyExecute(const Instruction *Inst,
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3629,7 +3629,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
// * The intrinsic is speculatable.
// * The select condition is not a vector, or the intrinsic does not
// perform cross-lane operations.
if (isLanewiseOperation(II))
if (isSafeToSpeculativelyExecuteWithVariableReplaced(&CI) &&
isLanewiseOperation(II))
for (Value *Op : II->args())
if (auto *Sel = dyn_cast<SelectInst>(Op))
if (Instruction *R = FoldOpIntoSelect(*II, Sel))
Expand Down

0 comments on commit 0e9d014

Please sign in to comment.