Skip to content

Commit 0e9d014

Browse files
committed
ValueTracking, InstSimplify: address review
1 parent b2a7446 commit 0e9d014

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4343,8 +4343,7 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
43434343
if (isa<PHINode>(I))
43444344
return nullptr;
43454345

4346-
if (Op->getType()->isVectorTy() &&
4347-
(!I->getType()->isVectorTy() || !isLanewiseOperation(I)))
4346+
if (Op->getType()->isVectorTy() && !isLanewiseOperation(I))
43484347
// For vector types, the simplification must hold per-lane, so forbid
43494348
// potentially cross-lane operations like shufflevector.
43504349
return nullptr;

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6950,6 +6950,7 @@ bool llvm::onlyUsedByLifetimeMarkersOrDroppableInsts(const Value *V) {
69506950
bool llvm::isLanewiseOperation(const Instruction *I) {
69516951
if (auto *II = dyn_cast<IntrinsicInst>(I)) {
69526952
switch (II->getIntrinsicID()) {
6953+
// TODO: expand this list.
69536954
case Intrinsic::ctlz:
69546955
case Intrinsic::cttz:
69556956
case Intrinsic::ctpop:
@@ -6967,8 +6968,8 @@ bool llvm::isLanewiseOperation(const Instruction *I) {
69676968
}
69686969
}
69696970
auto *Shuffle = dyn_cast<ShuffleVectorInst>(I);
6970-
return (!Shuffle || Shuffle->isIdentity() || Shuffle->isSelect()) &&
6971-
!isa<CallBase>(I) && !isa<BitCastInst>(I);
6971+
return (!Shuffle || Shuffle->isSelect()) &&
6972+
!isa<CallBase, BitCastInst, ExtractElementInst>(I);
69726973
}
69736974

69746975
bool llvm::isSafeToSpeculativelyExecute(const Instruction *Inst,

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3629,7 +3629,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
36293629
// * The intrinsic is speculatable.
36303630
// * The select condition is not a vector, or the intrinsic does not
36313631
// perform cross-lane operations.
3632-
if (isLanewiseOperation(II))
3632+
if (isSafeToSpeculativelyExecuteWithVariableReplaced(&CI) &&
3633+
isLanewiseOperation(II))
36333634
for (Value *Op : II->args())
36343635
if (auto *Sel = dyn_cast<SelectInst>(Op))
36353636
if (Instruction *R = FoldOpIntoSelect(*II, Sel))

0 commit comments

Comments
 (0)