diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index d6285dcd387..139b04bb6a8 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -899,8 +899,8 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS, // For vectors, we apply the same reasoning on a per-lane basis. auto *Base = GEPLHS->getPointerOperand(); if (GEPLHS->getType()->isVectorTy() && Base->getType()->isPointerTy()) { - int NumElts = cast(GEPLHS->getType())->getNumElements(); - Base = Builder.CreateVectorSplat(NumElts, Base); + auto EC = cast(GEPLHS->getType())->getElementCount(); + Base = Builder.CreateVectorSplat(EC, Base); } return new ICmpInst(Cond, Base, ConstantExpr::getPointerBitCastOrAddrSpaceCast( @@ -1885,8 +1885,7 @@ Instruction *InstCombinerImpl::foldICmpAndConstant(ICmpInst &Cmp, if (ExactLogBase2 != -1 && DL.isLegalInteger(ExactLogBase2 + 1)) { Type *NTy = IntegerType::get(Cmp.getContext(), ExactLogBase2 + 1); if (auto *AndVTy = dyn_cast(And->getType())) - NTy = FixedVectorType::get( - NTy, cast(AndVTy)->getNumElements()); + NTy = VectorType::get(NTy, AndVTy->getElementCount()); Value *Trunc = Builder.CreateTrunc(X, NTy); auto NewPred = Cmp.getPredicate() == CmpInst::ICMP_EQ ? CmpInst::ICMP_SGE : CmpInst::ICMP_SLT; @@ -2192,8 +2191,7 @@ Instruction *InstCombinerImpl::foldICmpShlConstant(ICmpInst &Cmp, DL.isLegalInteger(TypeBits - Amt)) { Type *TruncTy = IntegerType::get(Cmp.getContext(), TypeBits - Amt); if (auto *ShVTy = dyn_cast(ShType)) - TruncTy = FixedVectorType::get( - TruncTy, cast(ShVTy)->getNumElements()); + TruncTy = VectorType::get(TruncTy, ShVTy->getElementCount()); Constant *NewC = ConstantInt::get(TruncTy, C.ashr(*ShiftAmt).trunc(TypeBits - Amt)); return new ICmpInst(Pred, Builder.CreateTrunc(X, TruncTy), NewC); @@ -2827,8 +2825,7 @@ static Instruction *foldICmpBitCast(ICmpInst &Cmp, Type *NewType = Builder.getIntNTy(XType->getScalarSizeInBits()); if (auto *XVTy = dyn_cast(XType)) - NewType = FixedVectorType::get( - NewType, cast(XVTy)->getNumElements()); + NewType = VectorType::get(NewType, XVTy->getElementCount()); Value *NewBitcast = Builder.CreateBitCast(X, NewType); if (TrueIfSigned) return new ICmpInst(ICmpInst::ICMP_SLT, NewBitcast, @@ -3411,8 +3408,8 @@ static Value *foldICmpWithLowBitMaskedVal(ICmpInst &I, // those elements by copying an existing, defined, and safe scalar constant. Type *OpTy = M->getType(); auto *VecC = dyn_cast(M); - if (OpTy->isVectorTy() && VecC && VecC->containsUndefElement()) { - auto *OpVTy = cast(OpTy); + auto *OpVTy = dyn_cast(OpTy); + if (OpVTy && VecC && VecC->containsUndefElement()) { Constant *SafeReplacementConstant = nullptr; for (unsigned i = 0, e = OpVTy->getNumElements(); i != e; ++i) { if (!isa(VecC->getAggregateElement(i))) { diff --git a/test/Transforms/InstCombine/vscale_cmp.ll b/test/Transforms/InstCombine/vscale_cmp.ll index bbceab06e3f..e7b8a2e3e3f 100644 --- a/test/Transforms/InstCombine/vscale_cmp.ll +++ b/test/Transforms/InstCombine/vscale_cmp.ll @@ -9,3 +9,27 @@ define @sge( %x) { %cmp = icmp sge %x, zeroinitializer ret %cmp } + +define @gep_scalevector1(i32* %X) nounwind { +; CHECK-LABEL: @gep_scalevector1( +; CHECK-NEXT: [[S:%.*]] = insertelement undef, i32* [[X:%.*]], i32 0 +; CHECK-NEXT: [[C:%.*]] = icmp eq [[S]], zeroinitializer +; CHECK-NEXT: [[C1:%.*]] = shufflevector [[C]], undef, zeroinitializer +; CHECK-NEXT: ret [[C1]] +; + %A = getelementptr inbounds i32, i32* %X, zeroinitializer + %C = icmp eq %A, zeroinitializer + ret %C +} + +define @signbit_bitcast_fpext_scalevec( %x) { +; CHECK-LABEL: @signbit_bitcast_fpext_scalevec( +; CHECK-NEXT: [[TMP1:%.*]] = bitcast [[X:%.*]] to +; CHECK-NEXT: [[R:%.*]] = icmp slt [[TMP1]], zeroinitializer +; CHECK-NEXT: ret [[R]] +; + %f = fpext %x to + %b = bitcast %f to + %r = icmp slt %b, zeroinitializer + ret %r +}