@@ -797,15 +797,8 @@ static VPValue *optimizeEarlyExitInductionUser(VPlan &Plan,
797
797
VPValue *FirstActiveLane =
798
798
B.createNaryOp (VPInstruction::FirstActiveLane, Mask, DL);
799
799
Type *FirstActiveLaneType = TypeInfo.inferScalarType (FirstActiveLane);
800
- if (CanonicalIVType != FirstActiveLaneType) {
801
- Instruction::CastOps CastOp =
802
- CanonicalIVType->getScalarSizeInBits () <
803
- FirstActiveLaneType->getScalarSizeInBits ()
804
- ? Instruction::Trunc
805
- : Instruction::ZExt;
806
- FirstActiveLane =
807
- B.createScalarCast (CastOp, FirstActiveLane, CanonicalIVType, DL);
808
- }
800
+ FirstActiveLane = B.createScalarZExtOrTrunc (FirstActiveLane, CanonicalIVType,
801
+ FirstActiveLaneType, DL);
809
802
EndValue = B.createNaryOp (Instruction::Add, {EndValue, FirstActiveLane}, DL);
810
803
811
804
// `getOptimizableIVOf()` always returns the pre-incremented IV, so if it
@@ -2182,13 +2175,10 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
2182
2175
VPValue *MaxEVL = &Plan.getVF ();
2183
2176
// Emit VPScalarCastRecipe in preheader if VF is not a 32 bits integer.
2184
2177
VPBuilder Builder (LoopRegion->getPreheaderVPBB ());
2185
- if (unsigned VFSize =
2186
- TypeInfo.inferScalarType (MaxEVL)->getScalarSizeInBits ();
2187
- VFSize != 32 ) {
2188
- MaxEVL = Builder.createScalarCast (
2189
- VFSize > 32 ? Instruction::Trunc : Instruction::ZExt, MaxEVL,
2190
- Type::getInt32Ty (Ctx), DebugLoc ());
2191
- }
2178
+ MaxEVL = Builder.createScalarZExtOrTrunc (MaxEVL, Type::getInt32Ty (Ctx),
2179
+ TypeInfo.inferScalarType (MaxEVL),
2180
+ DebugLoc ());
2181
+
2192
2182
Builder.setInsertPoint (Header, Header->getFirstNonPhi ());
2193
2183
PrevEVL = Builder.createScalarPhi ({MaxEVL, &EVL}, DebugLoc (), " prev.evl" );
2194
2184
}
@@ -2286,6 +2276,7 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
2286
2276
return false ;
2287
2277
2288
2278
auto *CanonicalIVPHI = Plan.getCanonicalIV ();
2279
+ auto *CanIVTy = CanonicalIVPHI->getScalarType ();
2289
2280
VPValue *StartV = CanonicalIVPHI->getStartValue ();
2290
2281
2291
2282
// Create the ExplicitVectorLengthPhi recipe in the main loop.
@@ -2297,8 +2288,8 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
2297
2288
Instruction::Sub, {Plan.getTripCount (), EVLPhi}, DebugLoc (), " avl" );
2298
2289
if (MaxSafeElements) {
2299
2290
// Support for MaxSafeDist for correct loop emission.
2300
- VPValue *AVLSafe = Plan. getOrAddLiveIn (
2301
- ConstantInt::get (CanonicalIVPHI-> getScalarType () , *MaxSafeElements));
2291
+ VPValue *AVLSafe =
2292
+ Plan. getOrAddLiveIn ( ConstantInt::get (CanIVTy , *MaxSafeElements));
2302
2293
VPValue *Cmp = Builder.createICmp (ICmpInst::ICMP_ULT, AVL, AVLSafe);
2303
2294
AVL = Builder.createSelect (Cmp, AVL, AVLSafe, DebugLoc (), " safe_avl" );
2304
2295
}
@@ -2308,13 +2299,12 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
2308
2299
auto *CanonicalIVIncrement =
2309
2300
cast<VPInstruction>(CanonicalIVPHI->getBackedgeValue ());
2310
2301
Builder.setInsertPoint (CanonicalIVIncrement);
2311
- VPSingleDefRecipe *OpVPEVL = VPEVL;
2312
- if (unsigned IVSize = CanonicalIVPHI->getScalarType ()->getScalarSizeInBits ();
2313
- IVSize != 32 ) {
2314
- OpVPEVL = Builder.createScalarCast (
2315
- IVSize < 32 ? Instruction::Trunc : Instruction::ZExt, OpVPEVL,
2316
- CanonicalIVPHI->getScalarType (), CanonicalIVIncrement->getDebugLoc ());
2317
- }
2302
+ VPValue *OpVPEVL = VPEVL;
2303
+
2304
+ auto *I32Ty = Type::getInt32Ty (CanIVTy->getContext ());
2305
+ OpVPEVL = Builder.createScalarZExtOrTrunc (
2306
+ OpVPEVL, CanIVTy, I32Ty, CanonicalIVIncrement->getDebugLoc ());
2307
+
2318
2308
auto *NextEVLIV = Builder.createOverflowingOp (
2319
2309
Instruction::Add, {OpVPEVL, EVLPhi},
2320
2310
{CanonicalIVIncrement->hasNoUnsignedWrap (),
0 commit comments