[llvm] d139f65 - [SLP][NFC]Add another test for external phi user, NFC

via llvm-commits llvm-commits at lists.llvm.org
Tue May 26 17:59:38 PDT 2026


Author: Alexey Bataev
Date: 2026-05-26T20:59:33-04:00
New Revision: d139f653019ee8058eaadf5e5deda79ee8faf093

URL: https://github.com/llvm/llvm-project/commit/d139f653019ee8058eaadf5e5deda79ee8faf093
DIFF: https://github.com/llvm/llvm-project/commit/d139f653019ee8058eaadf5e5deda79ee8faf093.diff

LOG: [SLP][NFC]Add another test for external phi user, NFC



Reviewers: 

Pull Request: https://github.com/llvm/llvm-project/pull/199804

Added: 
    

Modified: 
    llvm/test/Transforms/SLPVectorizer/AArch64/lcssa-phi-extract-scale.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/SLPVectorizer/AArch64/lcssa-phi-extract-scale.ll b/llvm/test/Transforms/SLPVectorizer/AArch64/lcssa-phi-extract-scale.ll
index b3dbd84c3d731..4ad0e6934d7a5 100644
--- a/llvm/test/Transforms/SLPVectorizer/AArch64/lcssa-phi-extract-scale.ll
+++ b/llvm/test/Transforms/SLPVectorizer/AArch64/lcssa-phi-extract-scale.ll
@@ -1,8 +1,9 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
 ; RUN: opt -passes=slp-vectorizer -mtriple=aarch64-none-linux-gnu -mcpu=neoverse-n1 -S %s | FileCheck %s
-
+;
 declare void @sink_use(i32, i32, i32)
 
+; "bad" ordering: outer.latch after inner.body => LCSSA-phi users first.
 define double @test(ptr %obj, ptr %arr, i32 %n) {
 ; CHECK-LABEL: define double @test(
 ; CHECK-SAME: ptr [[OBJ:%.*]], ptr [[ARR:%.*]], i32 [[N:%.*]]) #[[ATTR0:[0-9]+]] {
@@ -211,3 +212,218 @@ exit:
   %mul = fmul double %div, 4.000000e+00
   ret double %mul
 }
+
+define double @test_inloop_first(ptr %obj, ptr %arr, i32 %n) {
+; CHECK-LABEL: define double @test_inloop_first(
+; CHECK-SAME: ptr [[OBJ:%.*]], ptr [[ARR:%.*]], i32 [[N:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:  [[ENTRY:.*]]:
+; CHECK-NEXT:    [[POS1:%.*]] = getelementptr inbounds i8, ptr [[OBJ]], i64 44
+; CHECK-NEXT:    [[COND_ENTER:%.*]] = icmp sgt i32 [[N]], 0
+; CHECK-NEXT:    br i1 [[COND_ENTER]], label %[[OUTER_PREHEADER:.*]], label %[[EXIT:.*]]
+; CHECK:       [[OUTER_PREHEADER]]:
+; CHECK-NEXT:    br label %[[OUTER_HEADER:.*]]
+; CHECK:       [[OUTER_HEADER]]:
+; CHECK-NEXT:    [[LOCAL_4_128:%.*]] = phi i32 [ 0, %[[OUTER_PREHEADER]] ], [ [[LCSSA_IV:%.*]], %[[OUTER_LATCH:.*]] ]
+; CHECK-NEXT:    [[LOCAL_3_127:%.*]] = phi i32 [ 0, %[[OUTER_PREHEADER]] ], [ [[LOCAL_3_16_LCSSA:%.*]], %[[OUTER_LATCH]] ]
+; CHECK-NEXT:    [[TMP0:%.*]] = phi <2 x i32> [ <i32 4, i32 16>, %[[OUTER_PREHEADER]] ], [ [[TMP9:%.*]], %[[OUTER_LATCH]] ]
+; CHECK-NEXT:    br label %[[INNER_HEADER:.*]]
+; CHECK:       [[INNER_HEADER]]:
+; CHECK-NEXT:    [[LOCAL_4_128420:%.*]] = phi i32 [ [[LOCAL_4_128]], %[[OUTER_HEADER]] ], [ [[INC:%.*]], %[[INNER_BODY:.*]] ]
+; CHECK-NEXT:    [[LOCAL_3_127421:%.*]] = phi i32 [ [[LOCAL_3_127]], %[[OUTER_HEADER]] ], [ [[LOCAL_3_16:%.*]], %[[INNER_BODY]] ]
+; CHECK-NEXT:    [[CHUNK_IV:%.*]] = phi i64 [ 0, %[[OUTER_HEADER]] ], [ [[CHUNK_IV_NEXT:%.*]], %[[INNER_BODY]] ]
+; CHECK-NEXT:    [[TMP1:%.*]] = phi <2 x i32> [ [[TMP0]], %[[OUTER_HEADER]] ], [ [[TMP15:%.*]], %[[INNER_BODY]] ]
+; CHECK-NEXT:    [[TMP2:%.*]] = extractelement <2 x i32> [[TMP1]], i32 0
+; CHECK-NEXT:    [[TMP3:%.*]] = icmp eq <2 x i32> [[TMP1]], zeroinitializer
+; CHECK-NEXT:    [[TMP4:%.*]] = add <2 x i32> [[TMP1]], splat (i32 -1)
+; CHECK-NEXT:    [[TMP5:%.*]] = select <2 x i1> [[TMP3]], <2 x i32> splat (i32 16), <2 x i32> [[TMP4]]
+; CHECK-NEXT:    [[TMP6:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> [[TMP5]], <4 x i32> <i32 1, i32 0, i32 2, i32 3>
+; CHECK-NEXT:    [[TMP7:%.*]] = icmp ult <4 x i32> [[TMP6]], splat (i32 17)
+; CHECK-NEXT:    [[TMP8:%.*]] = call i1 @llvm.vector.reduce.and.v4i1(<4 x i1> [[TMP7]])
+; CHECK-NEXT:    br i1 [[TMP8]], label %[[INNER_BODY]], label %[[DEOPT:.*]]
+; CHECK:       [[OUTER_LATCH]]:
+; CHECK-NEXT:    [[LOCAL_3_16_LCSSA]] = phi i32 [ [[LOCAL_3_16]], %[[INNER_BODY]] ]
+; CHECK-NEXT:    [[LCSSA_IV]] = phi i32 [ [[INC]], %[[INNER_BODY]] ]
+; CHECK-NEXT:    [[DOTNOT_LCSSA:%.*]] = phi i1 [ [[DOTNOT:%.*]], %[[INNER_BODY]] ]
+; CHECK-NEXT:    [[TMP9]] = phi <2 x i32> [ [[TMP15]], %[[INNER_BODY]] ]
+; CHECK-NEXT:    br i1 [[DOTNOT_LCSSA]], label %[[OUTER_HEADER]], label %[[EXIT_LOOP:.*]]
+; CHECK:       [[EXIT_LOOP]]:
+; CHECK-NEXT:    [[FINAL:%.*]] = phi i32 [ [[LOCAL_3_16_LCSSA]], %[[OUTER_LATCH]] ]
+; CHECK-NEXT:    [[RESULT:%.*]] = sitofp i32 [[FINAL]] to double
+; CHECK-NEXT:    br label %[[EXIT]]
+; CHECK:       [[INNER_BODY]]:
+; CHECK-NEXT:    [[CHUNK_IV_NEXT]] = add nuw nsw i64 [[CHUNK_IV]], 1
+; CHECK-NEXT:    [[V34:%.*]] = zext nneg i32 [[TMP2]] to i64
+; CHECK-NEXT:    [[V35:%.*]] = getelementptr inbounds nuw [4 x i8], ptr [[ARR]], i64 [[V34]]
+; CHECK-NEXT:    [[V36:%.*]] = load i32, ptr [[V35]], align 4
+; CHECK-NEXT:    [[TMP10:%.*]] = extractelement <2 x i32> [[TMP1]], i32 1
+; CHECK-NEXT:    [[V37:%.*]] = zext nneg i32 [[TMP10]] to i64
+; CHECK-NEXT:    [[V38:%.*]] = getelementptr inbounds nuw [4 x i8], ptr [[ARR]], i64 [[V37]]
+; CHECK-NEXT:    [[V39:%.*]] = load i32, ptr [[V38]], align 4
+; CHECK-NEXT:    [[V40:%.*]] = sub i32 [[V36]], [[V39]]
+; CHECK-NEXT:    [[V41:%.*]] = add nsw i32 [[V40]], 2147483647
+; CHECK-NEXT:    [[V42:%.*]] = icmp slt i32 [[V40]], 0
+; CHECK-NEXT:    [[SPEC_SELECT_I13:%.*]] = select i1 [[V42]], i32 [[V41]], i32 [[V40]]
+; CHECK-NEXT:    store i32 [[SPEC_SELECT_I13]], ptr [[V38]], align 4
+; CHECK-NEXT:    [[V43:%.*]] = sitofp i32 [[SPEC_SELECT_I13]] to double
+; CHECK-NEXT:    [[V44:%.*]] = fmul nnan double [[V43]], f0x3E00000000200000
+; CHECK-NEXT:    [[TMP11:%.*]] = extractelement <2 x i32> [[TMP5]], i32 0
+; CHECK-NEXT:    [[V45:%.*]] = zext nneg i32 [[TMP11]] to i64
+; CHECK-NEXT:    [[V46:%.*]] = getelementptr inbounds nuw [4 x i8], ptr [[ARR]], i64 [[V45]]
+; CHECK-NEXT:    [[V47:%.*]] = load i32, ptr [[V46]], align 4
+; CHECK-NEXT:    [[TMP12:%.*]] = extractelement <2 x i32> [[TMP5]], i32 1
+; CHECK-NEXT:    [[V48:%.*]] = zext nneg i32 [[TMP12]] to i64
+; CHECK-NEXT:    [[V49:%.*]] = getelementptr inbounds nuw [4 x i8], ptr [[ARR]], i64 [[V48]]
+; CHECK-NEXT:    [[V50:%.*]] = load i32, ptr [[V49]], align 4
+; CHECK-NEXT:    [[V51:%.*]] = sub i32 [[V47]], [[V50]]
+; CHECK-NEXT:    [[V52:%.*]] = add nsw i32 [[V51]], 2147483647
+; CHECK-NEXT:    [[V53:%.*]] = icmp slt i32 [[V51]], 0
+; CHECK-NEXT:    [[SPEC_SELECT_I:%.*]] = select i1 [[V53]], i32 [[V52]], i32 [[V51]]
+; CHECK-NEXT:    store i32 [[SPEC_SELECT_I]], ptr [[V49]], align 4
+; CHECK-NEXT:    [[TMP13:%.*]] = icmp eq <2 x i32> [[TMP5]], zeroinitializer
+; CHECK-NEXT:    [[TMP14:%.*]] = add nsw <2 x i32> [[TMP5]], splat (i32 -1)
+; CHECK-NEXT:    [[TMP15]] = select <2 x i1> [[TMP13]], <2 x i32> splat (i32 16), <2 x i32> [[TMP14]]
+; CHECK-NEXT:    store <2 x i32> [[TMP15]], ptr [[POS1]], align 4
+; CHECK-NEXT:    [[V56:%.*]] = sitofp i32 [[SPEC_SELECT_I]] to double
+; CHECK-NEXT:    [[V57:%.*]] = fmul nnan double [[V56]], f0x3E00000000200000
+; CHECK-NEXT:    [[V58:%.*]] = fmul nnan double [[V44]], [[V44]]
+; CHECK-NEXT:    [[V59:%.*]] = fmul nnan double [[V57]], [[V57]]
+; CHECK-NEXT:    [[V60:%.*]] = fadd double [[V58]], [[V59]]
+; CHECK-NEXT:    [[V61:%.*]] = fcmp ole double [[V60]], 1.000000e+00
+; CHECK-NEXT:    [[V62:%.*]] = zext i1 [[V61]] to i32
+; CHECK-NEXT:    [[LOCAL_3_16]] = add i32 [[V62]], [[LOCAL_3_127421]]
+; CHECK-NEXT:    [[INC]] = add nuw nsw i32 [[LOCAL_4_128420]], 1
+; CHECK-NEXT:    [[DOTNOT]] = icmp slt i32 [[INC]], [[N]]
+; CHECK-NEXT:    [[CHUNK_COND:%.*]] = icmp samesign ult i64 [[CHUNK_IV]], 32
+; CHECK-NEXT:    [[V64:%.*]] = and i1 [[DOTNOT]], [[CHUNK_COND]]
+; CHECK-NEXT:    br i1 [[V64]], label %[[INNER_HEADER]], label %[[OUTER_LATCH]]
+; CHECK:       [[DEOPT]]:
+; CHECK-NEXT:    %"$vphi.0419.lcssa" = phi i32 [ [[TMP2]], %[[INNER_HEADER]] ]
+; CHECK-NEXT:    [[LOCAL_4_128420_LCSSA:%.*]] = phi i32 [ [[LOCAL_4_128420]], %[[INNER_HEADER]] ]
+; CHECK-NEXT:    [[LOCAL_3_127421_LCSSA:%.*]] = phi i32 [ [[LOCAL_3_127421]], %[[INNER_HEADER]] ]
+; CHECK-NEXT:    call void @sink_use(i32 %"$vphi.0419.lcssa", i32 [[LOCAL_4_128420_LCSSA]], i32 [[LOCAL_3_127421_LCSSA]])
+; CHECK-NEXT:    ret double 0.000000e+00
+; CHECK:       [[EXIT]]:
+; CHECK-NEXT:    [[RET_VAL:%.*]] = phi double [ 0.000000e+00, %[[ENTRY]] ], [ [[RESULT]], %[[EXIT_LOOP]] ]
+; CHECK-NEXT:    [[NFP:%.*]] = sitofp i32 [[N]] to double
+; CHECK-NEXT:    [[DIV:%.*]] = fdiv double [[RET_VAL]], [[NFP]]
+; CHECK-NEXT:    [[MUL:%.*]] = fmul double [[DIV]], 4.000000e+00
+; CHECK-NEXT:    ret double [[MUL]]
+;
+entry:
+  %pos1 = getelementptr inbounds i8, ptr %obj, i64 44
+  %pos2 = getelementptr inbounds i8, ptr %obj, i64 48
+  %cond.enter = icmp sgt i32 %n, 0
+  br i1 %cond.enter, label %outer.preheader, label %exit
+
+outer.preheader:
+  br label %outer.header
+
+outer.header:
+  %"$vphi.1" = phi i32 [ 16, %outer.preheader ], [ %.sink6.i.lcssa, %outer.latch ]
+  %"$vphi.0" = phi i32 [ 4, %outer.preheader ], [ %.sink.i.lcssa, %outer.latch ]
+  %local_4_128 = phi i32 [ 0, %outer.preheader ], [ %lcssa.iv, %outer.latch ]
+  %local_3_127 = phi i32 [ 0, %outer.preheader ], [ %local_3_16.lcssa, %outer.latch ]
+  br label %inner.header
+
+inner.header:
+  %"$vphi.1418" = phi i32 [ %"$vphi.1", %outer.header ], [ %.sink6.i, %inner.body ]
+  %"$vphi.0419" = phi i32 [ %"$vphi.0", %outer.header ], [ %.sink.i, %inner.body ]
+  %local_4_128420 = phi i32 [ %local_4_128, %outer.header ], [ %inc, %inner.body ]
+  %local_3_127421 = phi i32 [ %local_3_127, %outer.header ], [ %local_3_16, %inner.body ]
+  %chunk.iv = phi i64 [ 0, %outer.header ], [ %chunk.iv.next, %inner.body ]
+  %c27 = icmp ult i32 %"$vphi.0419", 17
+  %c28 = icmp ult i32 %"$vphi.1418", 17
+  %wide.chk = and i1 %c28, %c27
+  %.not3.i17 = icmp eq i32 %"$vphi.0419", 0
+  %v29 = add i32 %"$vphi.0419", -1
+  %.sink.i18 = select i1 %.not3.i17, i32 16, i32 %v29
+  %c30 = icmp ult i32 %.sink.i18, 17
+  %wide.chk354 = and i1 %wide.chk, %c30
+  %.not4.i19 = icmp eq i32 %"$vphi.1418", 0
+  %v31 = add i32 %"$vphi.1418", -1
+  %.sink6.i20 = select i1 %.not4.i19, i32 16, i32 %v31
+  %c32 = icmp ult i32 %.sink6.i20, 17
+  %wide.chk355 = and i1 %c32, %wide.chk354
+  br i1 %wide.chk355, label %inner.body, label %deopt
+
+; outer.latch and exit.loop are placed BEFORE inner.body in this function.
+; When the LLVM IR parser reaches %.sink.i.lcssa here, it creates a forward
+; reference to %.sink.i (not yet defined). That forward-ref use is prepended
+; to %.sink.i's use list. Later, when inner.body is parsed, inner.body uses
+; of %.sink.i are prepended on top, so in-loop users appear first in the
+; reversed use list.
+outer.latch:
+  %.sink.i.lcssa = phi i32 [ %.sink.i, %inner.body ]
+  %.sink6.i.lcssa = phi i32 [ %.sink6.i, %inner.body ]
+  %local_3_16.lcssa = phi i32 [ %local_3_16, %inner.body ]
+  %lcssa.iv = phi i32 [ %inc, %inner.body ]
+  %.not.lcssa = phi i1 [ %.not, %inner.body ]
+  br i1 %.not.lcssa, label %outer.header, label %exit.loop
+
+exit.loop:
+  %final = phi i32 [ %local_3_16.lcssa, %outer.latch ]
+  %result = sitofp i32 %final to double
+  br label %exit
+
+inner.body:
+  %chunk.iv.next = add nuw nsw i64 %chunk.iv, 1
+  %v34 = zext nneg i32 %"$vphi.0419" to i64
+  %v35 = getelementptr inbounds nuw [4 x i8], ptr %arr, i64 %v34
+  %v36 = load i32, ptr %v35, align 4
+  %v37 = zext nneg i32 %"$vphi.1418" to i64
+  %v38 = getelementptr inbounds nuw [4 x i8], ptr %arr, i64 %v37
+  %v39 = load i32, ptr %v38, align 4
+  %v40 = sub i32 %v36, %v39
+  %v41 = add nsw i32 %v40, 2147483647
+  %v42 = icmp slt i32 %v40, 0
+  %spec.select.i13 = select i1 %v42, i32 %v41, i32 %v40
+  store i32 %spec.select.i13, ptr %v38, align 4
+  %v43 = sitofp i32 %spec.select.i13 to double
+  %v44 = fmul nnan double %v43, 0x3E00000000200000
+  %v45 = zext nneg i32 %.sink.i18 to i64
+  %v46 = getelementptr inbounds nuw [4 x i8], ptr %arr, i64 %v45
+  %v47 = load i32, ptr %v46, align 4
+  %v48 = zext nneg i32 %.sink6.i20 to i64
+  %v49 = getelementptr inbounds nuw [4 x i8], ptr %arr, i64 %v48
+  %v50 = load i32, ptr %v49, align 4
+  %v51 = sub i32 %v47, %v50
+  %v52 = add nsw i32 %v51, 2147483647
+  %v53 = icmp slt i32 %v51, 0
+  %spec.select.i = select i1 %v53, i32 %v52, i32 %v51
+  store i32 %spec.select.i, ptr %v49, align 4
+  %.not3.i = icmp eq i32 %.sink.i18, 0
+  %v54 = add nsw i32 %.sink.i18, -1
+  %.sink.i = select i1 %.not3.i, i32 16, i32 %v54
+  store i32 %.sink.i, ptr %pos1, align 4
+  %.not4.i = icmp eq i32 %.sink6.i20, 0
+  %v55 = add nsw i32 %.sink6.i20, -1
+  %.sink6.i = select i1 %.not4.i, i32 16, i32 %v55
+  store i32 %.sink6.i, ptr %pos2, align 8
+  %v56 = sitofp i32 %spec.select.i to double
+  %v57 = fmul nnan double %v56, 0x3E00000000200000
+  %v58 = fmul nnan double %v44, %v44
+  %v59 = fmul nnan double %v57, %v57
+  %v60 = fadd double %v58, %v59
+  %v61 = fcmp ole double %v60, 1.000000e+00
+  %v62 = zext i1 %v61 to i32
+  %local_3_16 = add i32 %v62, %local_3_127421
+  %inc = add nuw nsw i32 %local_4_128420, 1
+  %.not = icmp slt i32 %inc, %n
+  %chunk.cond = icmp samesign ult i64 %chunk.iv, 32
+  %v64 = and i1 %.not, %chunk.cond
+  br i1 %v64, label %inner.header, label %outer.latch
+
+deopt:
+  %"$vphi.0419.lcssa" = phi i32 [ %"$vphi.0419", %inner.header ]
+  %local_4_128420.lcssa = phi i32 [ %local_4_128420, %inner.header ]
+  %local_3_127421.lcssa = phi i32 [ %local_3_127421, %inner.header ]
+  call void @sink_use(i32 %"$vphi.0419.lcssa", i32 %local_4_128420.lcssa, i32 %local_3_127421.lcssa)
+  ret double 0.000000e+00
+
+exit:
+  %ret.val = phi double [ 0.000000e+00, %entry ], [ %result, %exit.loop ]
+  %nfp = sitofp i32 %n to double
+  %div = fdiv double %ret.val, %nfp
+  %mul = fmul double %div, 4.000000e+00
+  ret double %mul
+}


        


More information about the llvm-commits mailing list