[llvm] [DebugInfo][LoopVectorizer] Avoid dropping !dbg in optimizeForVFAndUF (PR #114243)

Stephen Tozer via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 4 07:43:45 PST 2024


https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/114243

>From e6628942a08225595d938ebcd1f6e8a7127c3c5d Mon Sep 17 00:00:00 2001
From: Stephen Tozer <stephen.tozer at sony.com>
Date: Fri, 25 Oct 2024 18:34:29 +0100
Subject: [PATCH 1/4] [DebugInfo][LoopVectorizer] Avoid dropping !dbg in
 optimizeForVFAndUF

Prior to this patch, optimizeForVFAndUF may optimize the branch condition
for a VPBasicblock to a constant, but unnecessarily drops the DILocation
attachment when it does so; this patch changes it to preserve the
DILocation.
---
 .../Transforms/Vectorize/VPlanTransforms.cpp  |   2 +-
 .../debugloc-optimize-vfuf-term.ll            | 108 ++++++++++++++++++
 2 files changed, 109 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Transforms/LoopVectorize/debugloc-optimize-vfuf-term.ll

diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 355781f955052e..df1ceedacdee99 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -699,7 +699,7 @@ void VPlanTransforms::optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF,
   LLVMContext &Ctx = SE.getContext();
   auto *BOC =
       new VPInstruction(VPInstruction::BranchOnCond,
-                        {Plan.getOrAddLiveIn(ConstantInt::getTrue(Ctx))});
+                        {Plan.getOrAddLiveIn(ConstantInt::getTrue(Ctx))}, Term->getDebugLoc());
 
   SmallVector<VPValue *> PossiblyDead(Term->operands());
   Term->eraseFromParent();
diff --git a/llvm/test/Transforms/LoopVectorize/debugloc-optimize-vfuf-term.ll b/llvm/test/Transforms/LoopVectorize/debugloc-optimize-vfuf-term.ll
new file mode 100644
index 00000000000000..0b38339e1772ff
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/debugloc-optimize-vfuf-term.ll
@@ -0,0 +1,108 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S < %s -passes=loop-vectorize -force-vector-width=2 | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define fastcc i32 @foo(i64 %a) {
+; CHECK-LABEL: define fastcc i32 @foo(
+; CHECK-SAME: i64 [[A:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*]]:
+; CHECK-NEXT:    [[WIDE_TRIP_COUNT:%.*]] = and i64 [[A]], 1
+; CHECK-NEXT:    [[TMP0:%.*]] = add nuw nsw i64 [[WIDE_TRIP_COUNT]], 1
+; CHECK-NEXT:    br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
+; CHECK:       [[VECTOR_PH]]:
+; CHECK-NEXT:    [[N_RND_UP:%.*]] = add i64 [[TMP0]], 1
+; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], 2
+; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
+; CHECK-NEXT:    [[TRIP_COUNT_MINUS_1:%.*]] = sub i64 [[TMP0]], 1
+; CHECK-NEXT:    [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <2 x i64> poison, i64 [[TRIP_COUNT_MINUS_1]], i64 0
+; CHECK-NEXT:    [[BROADCAST_SPLAT2:%.*]] = shufflevector <2 x i64> [[BROADCAST_SPLATINSERT1]], <2 x i64> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:    br label %[[VECTOR_BODY:.*]]
+; CHECK:       [[VECTOR_BODY]]:
+; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[PRED_STORE_CONTINUE4:.*]] ], !dbg [[DBG4:![0-9]+]]
+; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i64> poison, i64 [[INDEX]], i64 0
+; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i64> [[BROADCAST_SPLATINSERT]], <2 x i64> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:    [[VEC_IV:%.*]] = add <2 x i64> [[BROADCAST_SPLAT]], <i64 0, i64 1>
+; CHECK-NEXT:    [[TMP1:%.*]] = icmp ule <2 x i64> [[VEC_IV]], [[BROADCAST_SPLAT2]]
+; CHECK-NEXT:    [[TMP2:%.*]] = extractelement <2 x i1> [[TMP1]], i32 0
+; CHECK-NEXT:    br i1 [[TMP2]], label %[[PRED_STORE_IF:.*]], label %[[PRED_STORE_CONTINUE:.*]]
+; CHECK:       [[PRED_STORE_IF]]:
+; CHECK-NEXT:    [[TMP3:%.*]] = trunc i64 0 to i8, !dbg [[DBG8:![0-9]+]]
+; CHECK-NEXT:    store i8 [[TMP3]], ptr null, align 1, !dbg [[DBG9:![0-9]+]]
+; CHECK-NEXT:    br label %[[PRED_STORE_CONTINUE]]
+; CHECK:       [[PRED_STORE_CONTINUE]]:
+; CHECK-NEXT:    [[TMP4:%.*]] = extractelement <2 x i1> [[TMP1]], i32 1, !dbg [[DBG9]]
+; CHECK-NEXT:    br i1 [[TMP4]], label %[[PRED_STORE_IF3:.*]], label %[[PRED_STORE_CONTINUE4]], !dbg [[DBG9]]
+; CHECK:       [[PRED_STORE_IF3]]:
+; CHECK-NEXT:    [[TMP5:%.*]] = trunc i64 0 to i8, !dbg [[DBG8]]
+; CHECK-NEXT:    store i8 [[TMP5]], ptr null, align 1, !dbg [[DBG9]]
+; CHECK-NEXT:    br label %[[PRED_STORE_CONTINUE4]], !dbg [[DBG9]]
+; CHECK:       [[PRED_STORE_CONTINUE4]]:
+; CHECK-NEXT:    [[INDEX_NEXT]] = add i64 [[INDEX]], 2, !dbg [[DBG4]]
+; CHECK-NEXT:    br i1 true, label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !dbg [[DBG4]], !llvm.loop [[LOOP10:![0-9]+]]
+; CHECK:       [[MIDDLE_BLOCK]]:
+; CHECK-NEXT:    br i1 true, label %[[DO_BODY45_PREHEADER:.*]], label %[[SCALAR_PH]], !dbg [[DBG13:![0-9]+]]
+; CHECK:       [[SCALAR_PH]]:
+; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ], !dbg [[DBG4]]
+; CHECK-NEXT:    br label %[[DO_BODY:.*]]
+; CHECK:       [[DO_BODY]]:
+; CHECK-NEXT:    [[INDVARS_IV554:%.*]] = phi i64 [ [[INDVARS_IV_NEXT555:%.*]], %[[DO_BODY]] ], [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], !dbg [[DBG4]]
+; CHECK-NEXT:    [[CONV39:%.*]] = trunc i64 0 to i8, !dbg [[DBG8]]
+; CHECK-NEXT:    store i8 [[CONV39]], ptr null, align 1, !dbg [[DBG9]]
+; CHECK-NEXT:    [[INDVARS_IV_NEXT555]] = add i64 [[INDVARS_IV554]], 1, !dbg [[DBG14:![0-9]+]]
+; CHECK-NEXT:    [[EXITCOND557_NOT:%.*]] = icmp eq i64 [[INDVARS_IV554]], [[WIDE_TRIP_COUNT]], !dbg [[DBG15:![0-9]+]]
+; CHECK-NEXT:    br i1 [[EXITCOND557_NOT]], label %[[DO_BODY45_PREHEADER]], label %[[DO_BODY]], !dbg [[DBG13]], !llvm.loop [[LOOP16:![0-9]+]]
+; CHECK:       [[DO_BODY45_PREHEADER]]:
+; CHECK-NEXT:    ret i32 0
+;
+entry:
+  %wide.trip.count = and i64 %a, 1
+  br label %do.body
+
+do.body:                                          ; preds = %do.body, %entry
+  %indvars.iv554 = phi i64 [ %indvars.iv.next555, %do.body ], [ 0, %entry ], !dbg !4
+  %conv39 = trunc i64 0 to i8, !dbg !5
+  store i8 %conv39, ptr null, align 1, !dbg !6
+  %indvars.iv.next555 = add i64 %indvars.iv554, 1, !dbg !7
+  %exitcond557.not = icmp eq i64 %indvars.iv554, %wide.trip.count, !dbg !8
+  br i1 %exitcond557.not, label %do.body45.preheader, label %do.body, !dbg !9
+
+do.body45.preheader:                              ; preds = %do.body
+  ret i32 0
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0git (https://github.com/llvm/llvm-project.git 97cea5fecc5fa70842644da877c9547d4f34f6db)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "/home/gbtozers/dev/llvm-test-suite/CTMark/7zip/CPP/7zip/Compress/BZip2Decoder.cpp", directory: "/home/gbtozers/dev/llvm-test-suite-build", checksumkind: CSK_MD5, checksum: "ace37523c35f8079a0f00d337fc014dc")
+!2 = !{}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !DILocation(line: 4, scope: !21)
+!5 = !DILocation(line: 5, scope: !21)
+!6 = !DILocation(line: 6, scope: !21)
+!7 = !DILocation(line: 7, scope: !21)
+!8 = !DILocation(line: 8, scope: !21)
+!9 = !DILocation(line: 9, scope: !21)
+!20 = !DIFile(filename: "llvm-test-suite/CTMark/7zip/CPP/7zip/Compress/BZip2Decoder.cpp", directory: "/home/gbtozers/dev", checksumkind: CSK_MD5, checksum: "ace37523c35f8079a0f00d337fc014dc")
+!21 = distinct !DISubprogram(name: "ReadBlock", linkageName: "foo", scope: !20, file: !20, line: 113, type: !22, scopeLine: 116, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
+!22 = distinct !DISubroutineType(types: !2)
+;.
+; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], retainedTypes: [[META2]], globals: [[META2]], imports: [[META2]], splitDebugInlining: false, nameTableKind: None)
+; CHECK: [[META1]] = !DIFile(filename: "/home/gbtozers/dev/llvm-test-suite/CTMark/7zip/CPP/7zip/Compress/BZip2Decoder.cpp", directory: {{.*}})
+; CHECK: [[META2]] = !{}
+; CHECK: [[DBG4]] = !DILocation(line: 4, scope: [[META5:![0-9]+]])
+; CHECK: [[META5]] = distinct !DISubprogram(name: "ReadBlock", linkageName: "foo", scope: [[META6:![0-9]+]], file: [[META6]], line: 113, type: [[META7:![0-9]+]], scopeLine: 116, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META2]])
+; CHECK: [[META6]] = !DIFile(filename: "llvm-test-suite/CTMark/7zip/CPP/7zip/Compress/BZip2Decoder.cpp", directory: {{.*}})
+; CHECK: [[META7]] = distinct !DISubroutineType(types: [[META2]])
+; CHECK: [[DBG8]] = !DILocation(line: 5, scope: [[META5]])
+; CHECK: [[DBG9]] = !DILocation(line: 6, scope: [[META5]])
+; CHECK: [[LOOP10]] = distinct !{[[LOOP10]], [[META11:![0-9]+]], [[META12:![0-9]+]]}
+; CHECK: [[META11]] = !{!"llvm.loop.isvectorized", i32 1}
+; CHECK: [[META12]] = !{!"llvm.loop.unroll.runtime.disable"}
+; CHECK: [[DBG13]] = !DILocation(line: 9, scope: [[META5]])
+; CHECK: [[DBG14]] = !DILocation(line: 7, scope: [[META5]])
+; CHECK: [[DBG15]] = !DILocation(line: 8, scope: [[META5]])
+; CHECK: [[LOOP16]] = distinct !{[[LOOP16]], [[META12]], [[META11]]}
+;.

>From a551c2035e90d4827ef3a67b8e8dbd610f508acd Mon Sep 17 00:00:00 2001
From: Stephen Tozer <stephen.tozer at sony.com>
Date: Wed, 30 Oct 2024 15:45:18 +0000
Subject: [PATCH 2/4] clang-format

---
 llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index df1ceedacdee99..e9d2353a4519f7 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -697,9 +697,9 @@ void VPlanTransforms::optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF,
     return;
 
   LLVMContext &Ctx = SE.getContext();
-  auto *BOC =
-      new VPInstruction(VPInstruction::BranchOnCond,
-                        {Plan.getOrAddLiveIn(ConstantInt::getTrue(Ctx))}, Term->getDebugLoc());
+  auto *BOC = new VPInstruction(
+      VPInstruction::BranchOnCond,
+      {Plan.getOrAddLiveIn(ConstantInt::getTrue(Ctx))}, Term->getDebugLoc());
 
   SmallVector<VPValue *> PossiblyDead(Term->operands());
   Term->eraseFromParent();

>From c7b7b9bb42ed22861815d646709fecfe3947e882 Mon Sep 17 00:00:00 2001
From: Stephen Tozer <stephen.tozer at sony.com>
Date: Wed, 30 Oct 2024 21:51:10 +0000
Subject: [PATCH 3/4] Clean up test case

---
 .../debugloc-optimize-vfuf-term.ll            | 129 +++++++++---------
 1 file changed, 63 insertions(+), 66 deletions(-)

diff --git a/llvm/test/Transforms/LoopVectorize/debugloc-optimize-vfuf-term.ll b/llvm/test/Transforms/LoopVectorize/debugloc-optimize-vfuf-term.ll
index 0b38339e1772ff..9f4342f7442f54 100644
--- a/llvm/test/Transforms/LoopVectorize/debugloc-optimize-vfuf-term.ll
+++ b/llvm/test/Transforms/LoopVectorize/debugloc-optimize-vfuf-term.ll
@@ -1,12 +1,11 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
 ; RUN: opt -S < %s -passes=loop-vectorize -force-vector-width=2 | FileCheck %s
+;; Tests that when we simplify the loop-exit branch condition, we preserve the
+;; !dbg attachment for all loop-exit branches.
 
-target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-unknown-linux-gnu"
-
-define fastcc i32 @foo(i64 %a) {
-; CHECK-LABEL: define fastcc i32 @foo(
-; CHECK-SAME: i64 [[A:%.*]]) {
+define i32 @foo(i64 %a, ptr %p) {
+; CHECK-LABEL: define i32 @foo(
+; CHECK-SAME: i64 [[A:%.*]], ptr [[P:%.*]]) {
 ; CHECK-NEXT:  [[ENTRY:.*]]:
 ; CHECK-NEXT:    [[WIDE_TRIP_COUNT:%.*]] = and i64 [[A]], 1
 ; CHECK-NEXT:    [[TMP0:%.*]] = add nuw nsw i64 [[WIDE_TRIP_COUNT]], 1
@@ -20,7 +19,7 @@ define fastcc i32 @foo(i64 %a) {
 ; CHECK-NEXT:    [[BROADCAST_SPLAT2:%.*]] = shufflevector <2 x i64> [[BROADCAST_SPLATINSERT1]], <2 x i64> poison, <2 x i32> zeroinitializer
 ; CHECK-NEXT:    br label %[[VECTOR_BODY:.*]]
 ; CHECK:       [[VECTOR_BODY]]:
-; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[PRED_STORE_CONTINUE4:.*]] ], !dbg [[DBG4:![0-9]+]]
+; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[PRED_STORE_CONTINUE4:.*]] ], !dbg [[DBG3:![0-9]+]]
 ; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i64> poison, i64 [[INDEX]], i64 0
 ; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i64> [[BROADCAST_SPLATINSERT]], <2 x i64> poison, <2 x i32> zeroinitializer
 ; CHECK-NEXT:    [[VEC_IV:%.*]] = add <2 x i64> [[BROADCAST_SPLAT]], <i64 0, i64 1>
@@ -28,81 +27,79 @@ define fastcc i32 @foo(i64 %a) {
 ; CHECK-NEXT:    [[TMP2:%.*]] = extractelement <2 x i1> [[TMP1]], i32 0
 ; CHECK-NEXT:    br i1 [[TMP2]], label %[[PRED_STORE_IF:.*]], label %[[PRED_STORE_CONTINUE:.*]]
 ; CHECK:       [[PRED_STORE_IF]]:
-; CHECK-NEXT:    [[TMP3:%.*]] = trunc i64 0 to i8, !dbg [[DBG8:![0-9]+]]
-; CHECK-NEXT:    store i8 [[TMP3]], ptr null, align 1, !dbg [[DBG9:![0-9]+]]
+; CHECK-NEXT:    [[TMP3:%.*]] = trunc i64 0 to i8, !dbg [[DBG7:![0-9]+]]
+; CHECK-NEXT:    store i8 [[TMP3]], ptr [[P]], align 1, !dbg [[DBG8:![0-9]+]]
 ; CHECK-NEXT:    br label %[[PRED_STORE_CONTINUE]]
 ; CHECK:       [[PRED_STORE_CONTINUE]]:
-; CHECK-NEXT:    [[TMP4:%.*]] = extractelement <2 x i1> [[TMP1]], i32 1, !dbg [[DBG9]]
-; CHECK-NEXT:    br i1 [[TMP4]], label %[[PRED_STORE_IF3:.*]], label %[[PRED_STORE_CONTINUE4]], !dbg [[DBG9]]
+; CHECK-NEXT:    [[TMP4:%.*]] = extractelement <2 x i1> [[TMP1]], i32 1, !dbg [[DBG8]]
+; CHECK-NEXT:    br i1 [[TMP4]], label %[[PRED_STORE_IF3:.*]], label %[[PRED_STORE_CONTINUE4]], !dbg [[DBG8]]
 ; CHECK:       [[PRED_STORE_IF3]]:
-; CHECK-NEXT:    [[TMP5:%.*]] = trunc i64 0 to i8, !dbg [[DBG8]]
-; CHECK-NEXT:    store i8 [[TMP5]], ptr null, align 1, !dbg [[DBG9]]
-; CHECK-NEXT:    br label %[[PRED_STORE_CONTINUE4]], !dbg [[DBG9]]
+; CHECK-NEXT:    [[TMP5:%.*]] = trunc i64 0 to i8, !dbg [[DBG7]]
+; CHECK-NEXT:    store i8 [[TMP5]], ptr [[P]], align 1, !dbg [[DBG8]]
+; CHECK-NEXT:    br label %[[PRED_STORE_CONTINUE4]], !dbg [[DBG8]]
 ; CHECK:       [[PRED_STORE_CONTINUE4]]:
-; CHECK-NEXT:    [[INDEX_NEXT]] = add i64 [[INDEX]], 2, !dbg [[DBG4]]
-; CHECK-NEXT:    br i1 true, label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !dbg [[DBG4]], !llvm.loop [[LOOP10:![0-9]+]]
+; CHECK-NEXT:    [[INDEX_NEXT]] = add i64 [[INDEX]], 2, !dbg [[DBG3]]
+; CHECK-NEXT:    br i1 true, label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !dbg [[DBG3]], !llvm.loop [[LOOP9:![0-9]+]]
 ; CHECK:       [[MIDDLE_BLOCK]]:
-; CHECK-NEXT:    br i1 true, label %[[DO_BODY45_PREHEADER:.*]], label %[[SCALAR_PH]], !dbg [[DBG13:![0-9]+]]
+; CHECK-NEXT:    br i1 true, label %[[EXIT:.*]], label %[[SCALAR_PH]], !dbg [[DBG12:![0-9]+]]
 ; CHECK:       [[SCALAR_PH]]:
-; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ], !dbg [[DBG4]]
-; CHECK-NEXT:    br label %[[DO_BODY:.*]]
-; CHECK:       [[DO_BODY]]:
-; CHECK-NEXT:    [[INDVARS_IV554:%.*]] = phi i64 [ [[INDVARS_IV_NEXT555:%.*]], %[[DO_BODY]] ], [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], !dbg [[DBG4]]
-; CHECK-NEXT:    [[CONV39:%.*]] = trunc i64 0 to i8, !dbg [[DBG8]]
-; CHECK-NEXT:    store i8 [[CONV39]], ptr null, align 1, !dbg [[DBG9]]
-; CHECK-NEXT:    [[INDVARS_IV_NEXT555]] = add i64 [[INDVARS_IV554]], 1, !dbg [[DBG14:![0-9]+]]
-; CHECK-NEXT:    [[EXITCOND557_NOT:%.*]] = icmp eq i64 [[INDVARS_IV554]], [[WIDE_TRIP_COUNT]], !dbg [[DBG15:![0-9]+]]
-; CHECK-NEXT:    br i1 [[EXITCOND557_NOT]], label %[[DO_BODY45_PREHEADER]], label %[[DO_BODY]], !dbg [[DBG13]], !llvm.loop [[LOOP16:![0-9]+]]
-; CHECK:       [[DO_BODY45_PREHEADER]]:
+; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ], !dbg [[DBG3]]
+; CHECK-NEXT:    br label %[[LOOP:.*]]
+; CHECK:       [[LOOP]]:
+; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], %[[LOOP]] ], [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], !dbg [[DBG3]]
+; CHECK-NEXT:    [[CONV:%.*]] = trunc i64 0 to i8, !dbg [[DBG7]]
+; CHECK-NEXT:    store i8 [[CONV]], ptr [[P]], align 1, !dbg [[DBG8]]
+; CHECK-NEXT:    [[IV_NEXT]] = add i64 [[IV]], 1, !dbg [[DBG13:![0-9]+]]
+; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV]], [[WIDE_TRIP_COUNT]], !dbg [[DBG14:![0-9]+]]
+; CHECK-NEXT:    br i1 [[EXITCOND]], label %[[EXIT]], label %[[LOOP]], !dbg [[DBG12]], !llvm.loop [[LOOP15:![0-9]+]]
+; CHECK:       [[EXIT]]:
 ; CHECK-NEXT:    ret i32 0
 ;
 entry:
   %wide.trip.count = and i64 %a, 1
-  br label %do.body
+  br label %loop
 
-do.body:                                          ; preds = %do.body, %entry
-  %indvars.iv554 = phi i64 [ %indvars.iv.next555, %do.body ], [ 0, %entry ], !dbg !4
-  %conv39 = trunc i64 0 to i8, !dbg !5
-  store i8 %conv39, ptr null, align 1, !dbg !6
-  %indvars.iv.next555 = add i64 %indvars.iv554, 1, !dbg !7
-  %exitcond557.not = icmp eq i64 %indvars.iv554, %wide.trip.count, !dbg !8
-  br i1 %exitcond557.not, label %do.body45.preheader, label %do.body, !dbg !9
+loop:                                          ; preds = %loop, %entry
+  %iv = phi i64 [ %iv.next, %loop ], [ 0, %entry ], !dbg !3
+  %conv = trunc i64 0 to i8, !dbg !4
+  store i8 %conv, ptr %p, align 1, !dbg !5
+  %iv.next = add i64 %iv, 1, !dbg !6
+  %exitcond = icmp eq i64 %iv, %wide.trip.count, !dbg !7
+  br i1 %exitcond, label %exit, label %loop, !dbg !8
 
-do.body45.preheader:                              ; preds = %do.body
+exit:                              ; preds = %loop
   ret i32 0
 }
 
 !llvm.dbg.cu = !{!0}
-!llvm.module.flags = !{!3}
+!llvm.module.flags = !{!2}
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0git (https://github.com/llvm/llvm-project.git 97cea5fecc5fa70842644da877c9547d4f34f6db)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, splitDebugInlining: false, nameTableKind: None)
-!1 = !DIFile(filename: "/home/gbtozers/dev/llvm-test-suite/CTMark/7zip/CPP/7zip/Compress/BZip2Decoder.cpp", directory: "/home/gbtozers/dev/llvm-test-suite-build", checksumkind: CSK_MD5, checksum: "ace37523c35f8079a0f00d337fc014dc")
-!2 = !{}
-!3 = !{i32 2, !"Debug Info Version", i32 3}
-!4 = !DILocation(line: 4, scope: !21)
-!5 = !DILocation(line: 5, scope: !21)
-!6 = !DILocation(line: 6, scope: !21)
-!7 = !DILocation(line: 7, scope: !21)
-!8 = !DILocation(line: 8, scope: !21)
-!9 = !DILocation(line: 9, scope: !21)
-!20 = !DIFile(filename: "llvm-test-suite/CTMark/7zip/CPP/7zip/Compress/BZip2Decoder.cpp", directory: "/home/gbtozers/dev", checksumkind: CSK_MD5, checksum: "ace37523c35f8079a0f00d337fc014dc")
-!21 = distinct !DISubprogram(name: "ReadBlock", linkageName: "foo", scope: !20, file: !20, line: 113, type: !22, scopeLine: 116, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
-!22 = distinct !DISubroutineType(types: !2)
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0git")
+!1 = !DIFile(filename: "test.cpp", directory: "/")
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = !DILocation(line: 4, scope: !9)
+!4 = !DILocation(line: 5, scope: !9)
+!5 = !DILocation(line: 6, scope: !9)
+!6 = !DILocation(line: 7, scope: !9)
+!7 = !DILocation(line: 8, scope: !9)
+!8 = !DILocation(line: 9, scope: !9)
+!9 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 11, type: !10, unit: !0, retainedNodes: !11)
+!10 = distinct !DISubroutineType(types: !11)
+!11 = !{}
 ;.
-; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], retainedTypes: [[META2]], globals: [[META2]], imports: [[META2]], splitDebugInlining: false, nameTableKind: None)
-; CHECK: [[META1]] = !DIFile(filename: "/home/gbtozers/dev/llvm-test-suite/CTMark/7zip/CPP/7zip/Compress/BZip2Decoder.cpp", directory: {{.*}})
-; CHECK: [[META2]] = !{}
-; CHECK: [[DBG4]] = !DILocation(line: 4, scope: [[META5:![0-9]+]])
-; CHECK: [[META5]] = distinct !DISubprogram(name: "ReadBlock", linkageName: "foo", scope: [[META6:![0-9]+]], file: [[META6]], line: 113, type: [[META7:![0-9]+]], scopeLine: 116, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META2]])
-; CHECK: [[META6]] = !DIFile(filename: "llvm-test-suite/CTMark/7zip/CPP/7zip/Compress/BZip2Decoder.cpp", directory: {{.*}})
-; CHECK: [[META7]] = distinct !DISubroutineType(types: [[META2]])
-; CHECK: [[DBG8]] = !DILocation(line: 5, scope: [[META5]])
-; CHECK: [[DBG9]] = !DILocation(line: 6, scope: [[META5]])
-; CHECK: [[LOOP10]] = distinct !{[[LOOP10]], [[META11:![0-9]+]], [[META12:![0-9]+]]}
-; CHECK: [[META11]] = !{!"llvm.loop.isvectorized", i32 1}
-; CHECK: [[META12]] = !{!"llvm.loop.unroll.runtime.disable"}
-; CHECK: [[DBG13]] = !DILocation(line: 9, scope: [[META5]])
-; CHECK: [[DBG14]] = !DILocation(line: 7, scope: [[META5]])
-; CHECK: [[DBG15]] = !DILocation(line: 8, scope: [[META5]])
-; CHECK: [[LOOP16]] = distinct !{[[LOOP16]], [[META12]], [[META11]]}
+; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
+; CHECK: [[META1]] = !DIFile(filename: "test.cpp", directory: {{.*}})
+; CHECK: [[DBG3]] = !DILocation(line: 4, scope: [[META4:![0-9]+]])
+; CHECK: [[META4]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 11, type: [[META5:![0-9]+]], spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META6:![0-9]+]])
+; CHECK: [[META5]] = distinct !DISubroutineType(types: [[META6]])
+; CHECK: [[META6]] = !{}
+; CHECK: [[DBG7]] = !DILocation(line: 5, scope: [[META4]])
+; CHECK: [[DBG8]] = !DILocation(line: 6, scope: [[META4]])
+; CHECK: [[LOOP9]] = distinct !{[[LOOP9]], [[META10:![0-9]+]], [[META11:![0-9]+]]}
+; CHECK: [[META10]] = !{!"llvm.loop.isvectorized", i32 1}
+; CHECK: [[META11]] = !{!"llvm.loop.unroll.runtime.disable"}
+; CHECK: [[DBG12]] = !DILocation(line: 9, scope: [[META4]])
+; CHECK: [[DBG13]] = !DILocation(line: 7, scope: [[META4]])
+; CHECK: [[DBG14]] = !DILocation(line: 8, scope: [[META4]])
+; CHECK: [[LOOP15]] = distinct !{[[LOOP15]], [[META11]], [[META10]]}
 ;.

>From 2a6d0994151a992b37085430b5d98f9f34aedc85 Mon Sep 17 00:00:00 2001
From: Stephen Tozer <stephen.tozer at sony.com>
Date: Mon, 4 Nov 2024 15:43:28 +0000
Subject: [PATCH 4/4] Further test simplification

---
 .../debugloc-optimize-vfuf-term.ll            | 66 ++++++-------------
 1 file changed, 20 insertions(+), 46 deletions(-)

diff --git a/llvm/test/Transforms/LoopVectorize/debugloc-optimize-vfuf-term.ll b/llvm/test/Transforms/LoopVectorize/debugloc-optimize-vfuf-term.ll
index 9f4342f7442f54..04ce9562c04b57 100644
--- a/llvm/test/Transforms/LoopVectorize/debugloc-optimize-vfuf-term.ll
+++ b/llvm/test/Transforms/LoopVectorize/debugloc-optimize-vfuf-term.ll
@@ -3,60 +3,34 @@
 ;; Tests that when we simplify the loop-exit branch condition, we preserve the
 ;; !dbg attachment for all loop-exit branches.
 
-define i32 @foo(i64 %a, ptr %p) {
+define i32 @foo(ptr %p) {
 ; CHECK-LABEL: define i32 @foo(
-; CHECK-SAME: i64 [[A:%.*]], ptr [[P:%.*]]) {
+; CHECK-SAME: ptr [[P:%.*]]) {
 ; CHECK-NEXT:  [[ENTRY:.*]]:
-; CHECK-NEXT:    [[WIDE_TRIP_COUNT:%.*]] = and i64 [[A]], 1
-; CHECK-NEXT:    [[TMP0:%.*]] = add nuw nsw i64 [[WIDE_TRIP_COUNT]], 1
 ; CHECK-NEXT:    br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
 ; CHECK:       [[VECTOR_PH]]:
-; CHECK-NEXT:    [[N_RND_UP:%.*]] = add i64 [[TMP0]], 1
-; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], 2
-; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
-; CHECK-NEXT:    [[TRIP_COUNT_MINUS_1:%.*]] = sub i64 [[TMP0]], 1
-; CHECK-NEXT:    [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <2 x i64> poison, i64 [[TRIP_COUNT_MINUS_1]], i64 0
-; CHECK-NEXT:    [[BROADCAST_SPLAT2:%.*]] = shufflevector <2 x i64> [[BROADCAST_SPLATINSERT1]], <2 x i64> poison, <2 x i32> zeroinitializer
 ; CHECK-NEXT:    br label %[[VECTOR_BODY:.*]]
 ; CHECK:       [[VECTOR_BODY]]:
-; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[PRED_STORE_CONTINUE4:.*]] ], !dbg [[DBG3:![0-9]+]]
-; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i64> poison, i64 [[INDEX]], i64 0
-; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i64> [[BROADCAST_SPLATINSERT]], <2 x i64> poison, <2 x i32> zeroinitializer
-; CHECK-NEXT:    [[VEC_IV:%.*]] = add <2 x i64> [[BROADCAST_SPLAT]], <i64 0, i64 1>
-; CHECK-NEXT:    [[TMP1:%.*]] = icmp ule <2 x i64> [[VEC_IV]], [[BROADCAST_SPLAT2]]
-; CHECK-NEXT:    [[TMP2:%.*]] = extractelement <2 x i1> [[TMP1]], i32 0
-; CHECK-NEXT:    br i1 [[TMP2]], label %[[PRED_STORE_IF:.*]], label %[[PRED_STORE_CONTINUE:.*]]
-; CHECK:       [[PRED_STORE_IF]]:
-; CHECK-NEXT:    [[TMP3:%.*]] = trunc i64 0 to i8, !dbg [[DBG7:![0-9]+]]
-; CHECK-NEXT:    store i8 [[TMP3]], ptr [[P]], align 1, !dbg [[DBG8:![0-9]+]]
-; CHECK-NEXT:    br label %[[PRED_STORE_CONTINUE]]
-; CHECK:       [[PRED_STORE_CONTINUE]]:
-; CHECK-NEXT:    [[TMP4:%.*]] = extractelement <2 x i1> [[TMP1]], i32 1, !dbg [[DBG8]]
-; CHECK-NEXT:    br i1 [[TMP4]], label %[[PRED_STORE_IF3:.*]], label %[[PRED_STORE_CONTINUE4]], !dbg [[DBG8]]
-; CHECK:       [[PRED_STORE_IF3]]:
-; CHECK-NEXT:    [[TMP5:%.*]] = trunc i64 0 to i8, !dbg [[DBG7]]
-; CHECK-NEXT:    store i8 [[TMP5]], ptr [[P]], align 1, !dbg [[DBG8]]
-; CHECK-NEXT:    br label %[[PRED_STORE_CONTINUE4]], !dbg [[DBG8]]
-; CHECK:       [[PRED_STORE_CONTINUE4]]:
-; CHECK-NEXT:    [[INDEX_NEXT]] = add i64 [[INDEX]], 2, !dbg [[DBG3]]
-; CHECK-NEXT:    br i1 true, label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !dbg [[DBG3]], !llvm.loop [[LOOP9:![0-9]+]]
+; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ], !dbg [[DBG3:![0-9]+]]
+; CHECK-NEXT:    store i8 0, ptr [[P]], align 1, !dbg [[DBG7:![0-9]+]]
+; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2, !dbg [[DBG3]]
+; CHECK-NEXT:    br i1 true, label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !dbg [[DBG3]], !llvm.loop [[LOOP8:![0-9]+]]
 ; CHECK:       [[MIDDLE_BLOCK]]:
-; CHECK-NEXT:    br i1 true, label %[[EXIT:.*]], label %[[SCALAR_PH]], !dbg [[DBG12:![0-9]+]]
+; CHECK-NEXT:    br i1 true, label %[[EXIT:.*]], label %[[SCALAR_PH]], !dbg [[DBG11:![0-9]+]]
 ; CHECK:       [[SCALAR_PH]]:
-; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ], !dbg [[DBG3]]
+; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 2, %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ], !dbg [[DBG3]]
 ; CHECK-NEXT:    br label %[[LOOP:.*]]
 ; CHECK:       [[LOOP]]:
 ; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], %[[LOOP]] ], [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], !dbg [[DBG3]]
-; CHECK-NEXT:    [[CONV:%.*]] = trunc i64 0 to i8, !dbg [[DBG7]]
-; CHECK-NEXT:    store i8 [[CONV]], ptr [[P]], align 1, !dbg [[DBG8]]
+; CHECK-NEXT:    [[CONV:%.*]] = trunc i64 0 to i8, !dbg [[DBG12:![0-9]+]]
+; CHECK-NEXT:    store i8 [[CONV]], ptr [[P]], align 1, !dbg [[DBG7]]
 ; CHECK-NEXT:    [[IV_NEXT]] = add i64 [[IV]], 1, !dbg [[DBG13:![0-9]+]]
-; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV]], [[WIDE_TRIP_COUNT]], !dbg [[DBG14:![0-9]+]]
-; CHECK-NEXT:    br i1 [[EXITCOND]], label %[[EXIT]], label %[[LOOP]], !dbg [[DBG12]], !llvm.loop [[LOOP15:![0-9]+]]
+; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 1, !dbg [[DBG14:![0-9]+]]
+; CHECK-NEXT:    br i1 [[EXITCOND]], label %[[EXIT]], label %[[LOOP]], !dbg [[DBG11]], !llvm.loop [[LOOP15:![0-9]+]]
 ; CHECK:       [[EXIT]]:
 ; CHECK-NEXT:    ret i32 0
 ;
 entry:
-  %wide.trip.count = and i64 %a, 1
   br label %loop
 
 loop:                                          ; preds = %loop, %entry
@@ -64,7 +38,7 @@ loop:                                          ; preds = %loop, %entry
   %conv = trunc i64 0 to i8, !dbg !4
   store i8 %conv, ptr %p, align 1, !dbg !5
   %iv.next = add i64 %iv, 1, !dbg !6
-  %exitcond = icmp eq i64 %iv, %wide.trip.count, !dbg !7
+  %exitcond = icmp eq i64 %iv, 1, !dbg !7
   br i1 %exitcond, label %exit, label %loop, !dbg !8
 
 exit:                              ; preds = %loop
@@ -93,13 +67,13 @@ exit:                              ; preds = %loop
 ; CHECK: [[META4]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 11, type: [[META5:![0-9]+]], spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META6:![0-9]+]])
 ; CHECK: [[META5]] = distinct !DISubroutineType(types: [[META6]])
 ; CHECK: [[META6]] = !{}
-; CHECK: [[DBG7]] = !DILocation(line: 5, scope: [[META4]])
-; CHECK: [[DBG8]] = !DILocation(line: 6, scope: [[META4]])
-; CHECK: [[LOOP9]] = distinct !{[[LOOP9]], [[META10:![0-9]+]], [[META11:![0-9]+]]}
-; CHECK: [[META10]] = !{!"llvm.loop.isvectorized", i32 1}
-; CHECK: [[META11]] = !{!"llvm.loop.unroll.runtime.disable"}
-; CHECK: [[DBG12]] = !DILocation(line: 9, scope: [[META4]])
+; CHECK: [[DBG7]] = !DILocation(line: 6, scope: [[META4]])
+; CHECK: [[LOOP8]] = distinct !{[[LOOP8]], [[META9:![0-9]+]], [[META10:![0-9]+]]}
+; CHECK: [[META9]] = !{!"llvm.loop.isvectorized", i32 1}
+; CHECK: [[META10]] = !{!"llvm.loop.unroll.runtime.disable"}
+; CHECK: [[DBG11]] = !DILocation(line: 9, scope: [[META4]])
+; CHECK: [[DBG12]] = !DILocation(line: 5, scope: [[META4]])
 ; CHECK: [[DBG13]] = !DILocation(line: 7, scope: [[META4]])
 ; CHECK: [[DBG14]] = !DILocation(line: 8, scope: [[META4]])
-; CHECK: [[LOOP15]] = distinct !{[[LOOP15]], [[META11]], [[META10]]}
+; CHECK: [[LOOP15]] = distinct !{[[LOOP15]], [[META10]], [[META9]]}
 ;.



More information about the llvm-commits mailing list