@@ -3630,21 +3630,24 @@ void VPAliasLaneMaskRecipe::execute(VPTransformState &State) {
3630
3630
3631
3631
Value *Diff = Builder.CreateSub (SourceValue, SinkValue, " sub.diff" );
3632
3632
auto *Type = Diff->getType ();
3633
+ Value *Zero = ConstantInt::get (Type, 0 );
3633
3634
if (!WriteAfterRead)
3634
3635
Diff = Builder.CreateIntrinsic (
3635
3636
Intrinsic::abs, {Type},
3636
- {Diff, ConstantInt::getFalse (Builder.getInt1Ty ())});
3637
- Value *MemEltSize = ConstantInt::get (Type, ElementSize);
3638
- Value *DiffDiv = Builder.CreateSDiv (Diff, MemEltSize, " diff" );
3639
- // If the difference is negative then some elements may alias
3640
- Value *Cmp = Builder.CreateICmp (CmpInst::Predicate::ICMP_SLE, DiffDiv,
3641
- ConstantInt::get (Type, 0 ), " neg.compare" );
3637
+ {Diff, ConstantInt::getFalse (Builder.getInt1Ty ())}, nullptr , " sub.abs" );
3638
+
3639
+ Value *DiffDiv = Builder.CreateSDiv (Diff, Zero, " diff" );
3640
+ // If the difference is positive then some elements may alias
3641
+ auto CmpCode = WriteAfterRead ? CmpInst::Predicate::ICMP_SLE
3642
+ : CmpInst::Predicate::ICMP_EQ;
3643
+ Value *Cmp = Builder.CreateICmp (CmpCode, DiffDiv, Zero, " neg.compare" );
3644
+
3642
3645
// Splat the compare result then OR it with a lane mask
3643
3646
Value *Splat = Builder.CreateVectorSplat (State.VF , Cmp);
3644
3647
Value *DiffMask = Builder.CreateIntrinsic (
3645
3648
Intrinsic::get_active_lane_mask,
3646
- {VectorType::get (Builder.getInt1Ty (), State.VF ), Type},
3647
- { ConstantInt::get (Type, 0 ), DiffDiv}, nullptr , " ptr.diff.lane.mask" );
3649
+ {VectorType::get (Builder.getInt1Ty (), State.VF ), Type}, {Zero, DiffDiv},
3650
+ nullptr , " ptr.diff.lane.mask" );
3648
3651
Value *Or = Builder.CreateBinOp (Instruction::BinaryOps::Or, DiffMask, Splat);
3649
3652
State.set (this , Or, /* IsScalar=*/ false );
3650
3653
}
0 commit comments