diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -5571,14 +5571,9 @@ CmpInst::getSwappedPredicate(AltP0); CmpInst::Predicate CurrentPred = CI->getPredicate(); if (P0 == AltP0Swapped) - return (P0 == CurrentPred && - !areCompatibleCmpOps( - CI0->getOperand(0), CI0->getOperand(1), - CI->getOperand(0), CI->getOperand(1))) || - (AltP0 == CurrentPred && - !areCompatibleCmpOps( - CI0->getOperand(0), CI0->getOperand(1), - CI->getOperand(1), CI->getOperand(0))); + return !areCompatibleCmpOps( + CI0->getOperand(0), CI0->getOperand(1), CI->getOperand(0), + CI->getOperand(1)); return AltP0 == CurrentPred || AltP0Swapped == CurrentPred; } return I->getOpcode() == E->getAltOpcode(); @@ -7081,10 +7076,6 @@ V0 = Builder.CreateCmp(CI0->getPredicate(), LHS, RHS); auto *AltCI = cast(E->getAltOp()); CmpInst::Predicate AltPred = AltCI->getPredicate(); - unsigned AltIdx = - std::distance(E->Scalars.begin(), find(E->Scalars, AltCI)); - if (AltCI->getOperand(0) != E->getOperand(0)[AltIdx]) - AltPred = CmpInst::getSwappedPredicate(AltPred); V1 = Builder.CreateCmp(AltPred, LHS, RHS); } else { V0 = Builder.CreateCast( @@ -7121,14 +7112,9 @@ CmpInst::getSwappedPredicate(AltP0); CmpInst::Predicate CurrentPred = CI->getPredicate(); if (P0 == AltP0Swapped) - return (P0 == CurrentPred && - !areCompatibleCmpOps( - CI0->getOperand(0), CI0->getOperand(1), - CI->getOperand(0), CI->getOperand(1))) || - (AltP0 == CurrentPred && - !areCompatibleCmpOps( - CI0->getOperand(0), CI0->getOperand(1), - CI->getOperand(1), CI->getOperand(0))); + return !areCompatibleCmpOps( + CI0->getOperand(0), CI0->getOperand(1), CI->getOperand(0), + CI->getOperand(1)); return AltP0 == CurrentPred || AltP0Swapped == CurrentPred; } return I->getOpcode() == E->getAltOpcode(); diff --git a/llvm/test/Transforms/SLPVectorizer/X86/alternate-cmp-swapped-pred.ll b/llvm/test/Transforms/SLPVectorizer/X86/alternate-cmp-swapped-pred.ll --- a/llvm/test/Transforms/SLPVectorizer/X86/alternate-cmp-swapped-pred.ll +++ b/llvm/test/Transforms/SLPVectorizer/X86/alternate-cmp-swapped-pred.ll @@ -9,10 +9,11 @@ ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <8 x i16> , i16 [[CALL37:%.*]], i32 3 ; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt <8 x i16> [[TMP0]], [[SHUFFLE]] -; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <8 x i1> [[TMP2]], <8 x i1> [[TMP2]], <8 x i32> -; CHECK-NEXT: [[TMP4:%.*]] = zext <8 x i1> [[TMP3]] to <8 x i16> -; CHECK-NEXT: [[TMP5:%.*]] = call i16 @llvm.vector.reduce.add.v8i16(<8 x i16> [[TMP4]]) -; CHECK-NEXT: [[OP_EXTRA:%.*]] = add i16 [[TMP5]], 0 +; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt <8 x i16> [[TMP0]], [[SHUFFLE]] +; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <8 x i1> [[TMP2]], <8 x i1> [[TMP3]], <8 x i32> +; CHECK-NEXT: [[TMP5:%.*]] = zext <8 x i1> [[TMP4]] to <8 x i16> +; CHECK-NEXT: [[TMP6:%.*]] = call i16 @llvm.vector.reduce.add.v8i16(<8 x i16> [[TMP5]]) +; CHECK-NEXT: [[OP_EXTRA:%.*]] = add i16 [[TMP6]], 0 ; CHECK-NEXT: ret i16 [[OP_EXTRA]] ; entry: