Skip to content

Commit 1d531eb

Browse files
committed
Compare with zero instead
1 parent ed07c94 commit 1d531eb

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3630,21 +3630,24 @@ void VPAliasLaneMaskRecipe::execute(VPTransformState &State) {
36303630

36313631
Value *Diff = Builder.CreateSub(SourceValue, SinkValue, "sub.diff");
36323632
auto *Type = Diff->getType();
3633+
Value *Zero = ConstantInt::get(Type, 0);
36333634
if (!WriteAfterRead)
36343635
Diff = Builder.CreateIntrinsic(
36353636
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+
36423645
// Splat the compare result then OR it with a lane mask
36433646
Value *Splat = Builder.CreateVectorSplat(State.VF, Cmp);
36443647
Value *DiffMask = Builder.CreateIntrinsic(
36453648
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");
36483651
Value *Or = Builder.CreateBinOp(Instruction::BinaryOps::Or, DiffMask, Splat);
36493652
State.set(this, Or, /*IsScalar=*/false);
36503653
}

llvm/test/Transforms/LoopVectorize/AArch64/alias_mask.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ define dso_local void @alias_mask(ptr noalias %a, ptr %b, ptr %c, i32 %n) {
3030
; CHECK-NEXT: [[TMP6:%.*]] = call i64 @llvm.vscale.i64()
3131
; CHECK-NEXT: [[TMP7:%.*]] = mul i64 [[TMP6]], 16
3232
; CHECK-NEXT: [[SUB_DIFF:%.*]] = sub i64 [[B4]], [[C3]]
33-
; CHECK-NEXT: [[DIFF:%.*]] = sdiv i64 [[SUB_DIFF]], 1
33+
; CHECK-NEXT: [[DIFF:%.*]] = sdiv i64 [[SUB_DIFF]], 0
3434
; CHECK-NEXT: [[NEG_COMPARE:%.*]] = icmp sle i64 [[DIFF]], 0
3535
; CHECK-NEXT: [[DOTSPLATINSERT:%.*]] = insertelement <vscale x 16 x i1> poison, i1 [[NEG_COMPARE]], i64 0
3636
; CHECK-NEXT: [[DOTSPLAT:%.*]] = shufflevector <vscale x 16 x i1> [[DOTSPLATINSERT]], <vscale x 16 x i1> poison, <vscale x 16 x i32> zeroinitializer

llvm/test/Transforms/LoopVectorize/AArch64/induction-costs-sve.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ define void @iv_casts(ptr %dst, ptr %src, i32 %x, i64 %N) #0 {
122122
; PRED-NEXT: [[TMP9:%.*]] = extractelement <vscale x 16 x i64> [[BROADCAST_SPLAT6]], i32 0
123123
; PRED-NEXT: [[TMP10:%.*]] = extractelement <vscale x 16 x i64> [[BROADCAST_SPLAT]], i32 0
124124
; PRED-NEXT: [[SUB_DIFF:%.*]] = sub i64 [[TMP10]], [[TMP9]]
125-
; PRED-NEXT: [[DIFF:%.*]] = sdiv i64 [[SUB_DIFF]], 1
125+
; PRED-NEXT: [[DIFF:%.*]] = sdiv i64 [[SUB_DIFF]], 0
126126
; PRED-NEXT: [[NEG_COMPARE:%.*]] = icmp sle i64 [[DIFF]], 0
127127
; PRED-NEXT: [[DOTSPLATINSERT:%.*]] = insertelement <vscale x 16 x i1> poison, i1 [[NEG_COMPARE]], i64 0
128128
; PRED-NEXT: [[DOTSPLAT:%.*]] = shufflevector <vscale x 16 x i1> [[DOTSPLATINSERT]], <vscale x 16 x i1> poison, <vscale x 16 x i32> zeroinitializer

0 commit comments

Comments
 (0)