@@ -305,32 +305,7 @@ static bool isCommutative(Instruction *I) {
305
305
if (auto *Cmp = dyn_cast<CmpInst>(I))
306
306
return Cmp->isCommutative();
307
307
if (auto *BO = dyn_cast<BinaryOperator>(I))
308
- return BO->isCommutative() ||
309
- (BO->getOpcode() == Instruction::Sub &&
310
- !BO->hasNUsesOrMore(UsesLimit) &&
311
- all_of(
312
- BO->uses(),
313
- [](const Use &U) {
314
- // Commutative, if icmp eq/ne sub, 0
315
- ICmpInst::Predicate Pred;
316
- if (match(U.getUser(),
317
- m_ICmp(Pred, m_Specific(U.get()), m_Zero())) &&
318
- (Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_NE))
319
- return true;
320
- // Commutative, if abs(sub nsw, true) or abs(sub, false).
321
- ConstantInt *Flag;
322
- return match(U.getUser(),
323
- m_Intrinsic<Intrinsic::abs>(
324
- m_Specific(U.get()), m_ConstantInt(Flag))) &&
325
- (!cast<Instruction>(U.get())->hasNoSignedWrap() ||
326
- Flag->isOne());
327
- })) ||
328
- (BO->getOpcode() == Instruction::FSub &&
329
- !BO->hasNUsesOrMore(UsesLimit) &&
330
- all_of(BO->uses(), [](const Use &U) {
331
- return match(U.getUser(),
332
- m_Intrinsic<Intrinsic::fabs>(m_Specific(U.get())));
333
- }));
308
+ return BO->isCommutative();
334
309
return I->isCommutative();
335
310
}
336
311
@@ -6863,7 +6838,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
6863
6838
6864
6839
// Sort operands of the instructions so that each side is more likely to
6865
6840
// have the same opcode.
6866
- if (isa<BinaryOperator>(VL0) && isCommutative(VL0 )) {
6841
+ if (isa<BinaryOperator>(VL0) && VL0-> isCommutative()) {
6867
6842
ValueList Left, Right;
6868
6843
reorderInputsAccordingToOpcode(VL, Left, Right, *this);
6869
6844
TE->setOperand(0, Left);
@@ -12591,15 +12566,8 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
12591
12566
static_cast<Instruction::BinaryOps>(E->getOpcode()), LHS,
12592
12567
RHS);
12593
12568
propagateIRFlags(V, E->Scalars, VL0, It == MinBWs.end());
12594
- if (auto *I = dyn_cast<Instruction>(V)) {
12569
+ if (auto *I = dyn_cast<Instruction>(V))
12595
12570
V = propagateMetadata(I, E->Scalars);
12596
- // Drop nuw flags for abs(sub(commutative), true).
12597
- if (!MinBWs.contains(E) && ShuffleOrOp == Instruction::Sub &&
12598
- any_of(E->Scalars, [](Value *V) {
12599
- return isCommutative(cast<Instruction>(V));
12600
- }))
12601
- I->setHasNoUnsignedWrap(/*b=*/false);
12602
- }
12603
12571
12604
12572
V = FinalShuffle(V, E, VecTy);
12605
12573
@@ -12925,19 +12893,6 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
12925
12893
12926
12894
propagateIRFlags(V0, OpScalars, E->getMainOp(), It == MinBWs.end());
12927
12895
propagateIRFlags(V1, AltScalars, E->getAltOp(), It == MinBWs.end());
12928
- auto DropNuwFlag = [&](Value *Vec, unsigned Opcode) {
12929
- // Drop nuw flags for abs(sub(commutative), true).
12930
- if (auto *I = dyn_cast<Instruction>(Vec);
12931
- I && Opcode == Instruction::Sub && !MinBWs.contains(E) &&
12932
- any_of(E->Scalars, [](Value *V) {
12933
- auto *I = cast<Instruction>(V);
12934
- return I->getOpcode() == Instruction::Sub &&
12935
- isCommutative(cast<Instruction>(V));
12936
- }))
12937
- I->setHasNoUnsignedWrap(/*b=*/false);
12938
- };
12939
- DropNuwFlag(V0, E->getOpcode());
12940
- DropNuwFlag(V1, E->getAltOpcode());
12941
12896
12942
12897
Value *V = Builder.CreateShuffleVector(V0, V1, Mask);
12943
12898
if (auto *I = dyn_cast<Instruction>(V)) {
0 commit comments