[llvm] f0f666b - [LoopPeel] Add peeling tests with debug value and pointer inductions
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed May 28 02:09:05 PDT 2025
- Previous message: [llvm] 6296dd2 - [LoopIdiom] Use m_scev_AffineAddRec with Loop matcher (NFC) (#141660)
- Next message: [llvm] [P10][XXEVAL] Exploit xxeval instruction for cases of the ternary(A, X, and(B, C)), ternary(A, X, B), ternary(A, X, C), ternary(A, X, xor(B, C)) forms. (PR #141733)
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Author: Florian Hahn
Date: 2025-05-28T10:07:02+01:00
New Revision: f0f666bc3262f0ca6c7225116945e9feb67c14d0
URL: https://github.com/llvm/llvm-project/commit/f0f666bc3262f0ca6c7225116945e9feb67c14d0
DIFF: https://github.com/llvm/llvm-project/commit/f0f666bc3262f0ca6c7225116945e9feb67c14d0.diff
LOG: [LoopPeel] Add peeling tests with debug value and pointer inductions
Adds extra test coverage for https://github.com/llvm/llvm-project/pull/140792.
Added:
llvm/test/Transforms/LoopUnroll/peel-last-iteration-debug.ll
llvm/test/Transforms/LoopUnroll/peel-last-iteration-pointer-inductions.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/LoopUnroll/peel-last-iteration-debug.ll b/llvm/test/Transforms/LoopUnroll/peel-last-iteration-debug.ll
new file mode 100644
index 0000000000000..acbc12b3e3e5f
--- /dev/null
+++ b/llvm/test/Transforms/LoopUnroll/peel-last-iteration-debug.ll
@@ -0,0 +1,76 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -p loop-unroll -unroll-full-max-count=0 -S %s | FileCheck %s
+
+declare void @foo(i32)
+
+define void @test_dbg_value_in_exit_block() {
+; CHECK-LABEL: define void @test_dbg_value_in_exit_block() {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: br label %[[LOOP:.*]]
+; CHECK: [[LOOP]]:
+; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[INC:%.*]], %[[LOOP]] ]
+; CHECK-NEXT: call void @foo(i32 0)
+; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[IV]], 1
+; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INC]], 20
+; CHECK-NEXT: br i1 [[EXITCOND]], label %[[LOOP]], label %[[EXIT_PEEL_BEGIN:.*]], !llvm.loop [[LOOP4:![0-9]+]]
+; CHECK: [[EXIT_PEEL_BEGIN]]:
+; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ [[INC]], %[[LOOP]] ]
+; CHECK-NEXT: #dbg_value(float poison, [[META6:![0-9]+]], !DIExpression(), [[META11:![0-9]+]])
+; CHECK-NEXT: br label %[[LOOP_PEEL:.*]]
+; CHECK: [[LOOP_PEEL]]:
+; CHECK-NEXT: [[CMP2_PEEL:%.*]] = icmp eq i32 [[TMP0]], 20
+; CHECK-NEXT: [[SEL_PEEL:%.*]] = select i1 [[CMP2_PEEL]], i32 1, i32 0
+; CHECK-NEXT: call void @foo(i32 [[SEL_PEEL]])
+; CHECK-NEXT: [[INC_PEEL:%.*]] = add i32 [[TMP0]], 1
+; CHECK-NEXT: [[EXITCOND_PEEL:%.*]] = icmp ne i32 [[INC_PEEL]], 21
+; CHECK-NEXT: br i1 [[EXITCOND_PEEL]], label %[[EXIT_PEEL_NEXT:.*]], label %[[EXIT_PEEL_NEXT]]
+; CHECK: [[EXIT_PEEL_NEXT]]:
+; CHECK-NEXT: br label %[[LOOP_PEEL_NEXT:.*]]
+; CHECK: [[LOOP_PEEL_NEXT]]:
+; CHECK-NEXT: br label %[[EXIT:.*]]
+; CHECK: [[EXIT]]:
+; CHECK-NEXT: ret void
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [ 0, %entry ], [ %inc, %loop ]
+ %cmp2 = icmp eq i32 %iv, 20
+ %sel = select i1 %cmp2, i32 1, i32 0
+ call void @foo(i32 %sel)
+ %inc = add i32 %iv, 1
+ %exitcond = icmp ne i32 %inc, 21
+ br i1 %exitcond, label %loop, label %exit
+
+exit:
+ #dbg_value(float poison, !4, !DIExpression(), !9)
+ ret void
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 21.0.0git", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "repro.c", directory: "/", checksumkind: CSK_MD5, checksum: "3a182b2d218eb10b64164b06427cef3c")
+!2 = !{}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !DILocalVariable(name: "m_2", scope: !5, file: !1, line: 4, type: !8)
+!5 = distinct !DISubprogram(name: "test_dbg_value_in_exit_block", scope: !1, file: !1, line: 3, type: !6, scopeLine: 3, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
+!6 = !DISubroutineType(types: !7)
+!7 = !{null}
+!8 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
+!9 = !DILocation(line: 0, scope: !5)
+;.
+; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None)
+; CHECK: [[META1]] = !DIFile(filename: "{{.*}}repro.c", directory: {{.*}})
+; CHECK: [[META2]] = !{}
+; CHECK: [[LOOP4]] = distinct !{[[LOOP4]], [[META5:![0-9]+]]}
+; CHECK: [[META5]] = !{!"llvm.loop.peeled.count", i32 1}
+; CHECK: [[META6]] = !DILocalVariable(name: "m_2", scope: [[META7:![0-9]+]], file: [[META1]], line: 4, type: [[META10:![0-9]+]])
+; CHECK: [[META7]] = distinct !DISubprogram(name: "test_dbg_value_in_exit_block", scope: [[META1]], file: [[META1]], line: 3, type: [[META8:![0-9]+]], scopeLine: 3, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META2]])
+; CHECK: [[META8]] = !DISubroutineType(types: [[META9:![0-9]+]])
+; CHECK: [[META9]] = !{null}
+; CHECK: [[META10]] = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
+; CHECK: [[META11]] = !DILocation(line: 0, scope: [[META7]])
+;.
diff --git a/llvm/test/Transforms/LoopUnroll/peel-last-iteration-pointer-inductions.ll b/llvm/test/Transforms/LoopUnroll/peel-last-iteration-pointer-inductions.ll
new file mode 100644
index 0000000000000..8f2c89da9ab2b
--- /dev/null
+++ b/llvm/test/Transforms/LoopUnroll/peel-last-iteration-pointer-inductions.ll
@@ -0,0 +1,46 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -p loop-unroll -unroll-full-max-count=0 -S %s | FileCheck %s
+
+declare void @foo()
+
+define void @test_peel_last_pointer_induction(ptr %src, i64 %offset) {
+; CHECK-LABEL: define void @test_peel_last_pointer_induction(
+; CHECK-SAME: ptr [[SRC:%.*]], i64 [[OFFSET:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: [[END:%.*]] = getelementptr i8, ptr [[SRC]], i64 [[OFFSET]]
+; CHECK-NEXT: br label %[[LOOP_HEADER:.*]]
+; CHECK: [[LOOP_HEADER]]:
+; CHECK-NEXT: [[PTR_IV:%.*]] = phi ptr [ [[SRC]], %[[ENTRY]] ], [ [[PTR_IV_NEXT:%.*]], %[[LOOP_LATCH:.*]] ]
+; CHECK-NEXT: [[PTR_IV_NEXT]] = getelementptr nusw i8, ptr [[PTR_IV]], i64 1
+; CHECK-NEXT: [[CMP3_NOT:%.*]] = icmp eq ptr [[PTR_IV_NEXT]], [[END]]
+; CHECK-NEXT: br i1 [[CMP3_NOT]], label %[[LOOP_LATCH]], label %[[THEN:.*]]
+; CHECK: [[THEN]]:
+; CHECK-NEXT: call void @foo()
+; CHECK-NEXT: br label %[[LOOP_LATCH]]
+; CHECK: [[LOOP_LATCH]]:
+; CHECK-NEXT: [[EC:%.*]] = icmp eq ptr [[PTR_IV_NEXT]], [[END]]
+; CHECK-NEXT: br i1 [[EC]], label %[[EXIT:.*]], label %[[LOOP_HEADER]]
+; CHECK: [[EXIT]]:
+; CHECK-NEXT: ret void
+;
+entry:
+ %end = getelementptr i8, ptr %src, i64 %offset
+ br label %loop.header
+
+loop.header:
+ %ptr.iv = phi ptr [ %src, %entry ], [ %ptr.iv.next, %loop.latch ]
+ %ptr.iv.next = getelementptr nusw i8, ptr %ptr.iv, i64 1
+ %cmp3.not = icmp eq ptr %ptr.iv.next, %end
+ br i1 %cmp3.not, label %loop.latch, label %then
+
+then:
+ call void @foo()
+ br label %loop.latch
+
+loop.latch:
+ %ec = icmp eq ptr %ptr.iv.next, %end
+ br i1 %ec, label %exit, label %loop.header
+
+exit:
+ ret void
+}
- Previous message: [llvm] 6296dd2 - [LoopIdiom] Use m_scev_AffineAddRec with Loop matcher (NFC) (#141660)
- Next message: [llvm] [P10][XXEVAL] Exploit xxeval instruction for cases of the ternary(A, X, and(B, C)), ternary(A, X, B), ternary(A, X, C), ternary(A, X, xor(B, C)) forms. (PR #141733)
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the llvm-commits
mailing list