@@ -3270,21 +3270,24 @@ void VPAliasLaneMaskRecipe::execute(VPTransformState &State) {
3270
3270
3271
3271
Value *Diff = Builder.CreateSub (SourceValue, SinkValue, " sub.diff" );
3272
3272
auto *Type = Diff->getType ();
3273
+ Value *Zero = ConstantInt::get (Type, 0 );
3273
3274
if (!WriteAfterRead)
3274
3275
Diff = Builder.CreateIntrinsic (
3275
3276
Intrinsic::abs, {Type},
3276
- {Diff, ConstantInt::getFalse (Builder.getInt1Ty ())});
3277
- Value *MemEltSize = ConstantInt::get (Type, ElementSize);
3278
- Value *DiffDiv = Builder.CreateSDiv (Diff, MemEltSize, " diff" );
3279
- // If the difference is negative then some elements may alias
3280
- Value *Cmp = Builder.CreateICmp (CmpInst::Predicate::ICMP_SLE, DiffDiv,
3281
- ConstantInt::get (Type, 0 ), " neg.compare" );
3277
+ {Diff, ConstantInt::getFalse (Builder.getInt1Ty ())}, nullptr , " sub.abs" );
3278
+
3279
+ Value *DiffDiv = Builder.CreateSDiv (Diff, Zero, " diff" );
3280
+ // If the difference is positive then some elements may alias
3281
+ auto CmpCode = WriteAfterRead ? CmpInst::Predicate::ICMP_SLE
3282
+ : CmpInst::Predicate::ICMP_EQ;
3283
+ Value *Cmp = Builder.CreateICmp (CmpCode, DiffDiv, Zero, " neg.compare" );
3284
+
3282
3285
// Splat the compare result then OR it with a lane mask
3283
3286
Value *Splat = Builder.CreateVectorSplat (State.VF , Cmp);
3284
3287
Value *DiffMask = Builder.CreateIntrinsic (
3285
3288
Intrinsic::get_active_lane_mask,
3286
- {VectorType::get (Builder.getInt1Ty (), State.VF ), Type},
3287
- { ConstantInt::get (Type, 0 ), DiffDiv}, nullptr , " ptr.diff.lane.mask" );
3289
+ {VectorType::get (Builder.getInt1Ty (), State.VF ), Type}, {Zero, DiffDiv},
3290
+ nullptr , " ptr.diff.lane.mask" );
3288
3291
Value *Or = Builder.CreateBinOp (Instruction::BinaryOps::Or, DiffMask, Splat);
3289
3292
State.set (this , Or, /* IsScalar=*/ false );
3290
3293
}
0 commit comments