[llvm] 4f869e0 - [LoopPeel] Add test for peeling last iteration with non-trivial BTC.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed May 21 14:29:41 PDT 2025
Author: Florian Hahn
Date: 2025-05-21T22:28:26+01:00
New Revision: 4f869e0f5c8ea29708f2f3cb8408e3827f09c904
URL: https://github.com/llvm/llvm-project/commit/4f869e0f5c8ea29708f2f3cb8408e3827f09c904
DIFF: https://github.com/llvm/llvm-project/commit/4f869e0f5c8ea29708f2f3cb8408e3827f09c904.diff
LOG: [LoopPeel] Add test for peeling last iteration with non-trivial BTC.
Additional test to https://github.com/llvm/llvm-project/pull/140792 with
different SCEV expansion costs.
Added:
llvm/test/Transforms/LoopUnroll/peel-last-iteration-expansion-cost.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/LoopUnroll/peel-last-iteration-expansion-cost.ll b/llvm/test/Transforms/LoopUnroll/peel-last-iteration-expansion-cost.ll
new file mode 100644
index 0000000000000..342c70170fef3
--- /dev/null
+++ b/llvm/test/Transforms/LoopUnroll/peel-last-iteration-expansion-cost.ll
@@ -0,0 +1,61 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -p loop-unroll -scev-cheap-expansion-budget=2 -S %s | FileCheck --check-prefix=BUDGET2 %s
+; RUN: opt -p loop-unroll -scev-cheap-expansion-budget=3 -S %s | FileCheck --check-prefix=BUDGET3 %s
+
+define i32 @test_expansion_cost_2(i32 %start, i32 %end) {
+; BUDGET2-LABEL: define i32 @test_expansion_cost_2(
+; BUDGET2-SAME: i32 [[START:%.*]], i32 [[END:%.*]]) {
+; BUDGET2-NEXT: [[ENTRY:.*]]:
+; BUDGET2-NEXT: [[SUB:%.*]] = add i32 [[END]], -1
+; BUDGET2-NEXT: br label %[[LOOP_HEADER:.*]]
+; BUDGET2: [[LOOP_HEADER]]:
+; BUDGET2-NEXT: [[IV:%.*]] = phi i32 [ [[START]], %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP_LATCH:.*]] ]
+; BUDGET2-NEXT: [[C:%.*]] = icmp eq i32 [[IV]], [[SUB]]
+; BUDGET2-NEXT: br i1 [[C]], label %[[THEN:.*]], label %[[LOOP_LATCH]]
+; BUDGET2: [[THEN]]:
+; BUDGET2-NEXT: br label %[[LOOP_LATCH]]
+; BUDGET2: [[LOOP_LATCH]]:
+; BUDGET2-NEXT: [[IV_NEXT]] = add nsw i32 [[IV]], 1
+; BUDGET2-NEXT: [[EC:%.*]] = icmp eq i32 [[IV_NEXT]], [[END]]
+; BUDGET2-NEXT: br i1 [[EC]], label %[[EXIT:.*]], label %[[LOOP_HEADER]]
+; BUDGET2: [[EXIT]]:
+; BUDGET2-NEXT: ret i32 0
+;
+; BUDGET3-LABEL: define i32 @test_expansion_cost_2(
+; BUDGET3-SAME: i32 [[START:%.*]], i32 [[END:%.*]]) {
+; BUDGET3-NEXT: [[ENTRY:.*]]:
+; BUDGET3-NEXT: [[SUB:%.*]] = add i32 [[END]], -1
+; BUDGET3-NEXT: br label %[[LOOP_HEADER:.*]]
+; BUDGET3: [[LOOP_HEADER]]:
+; BUDGET3-NEXT: [[TMP3:%.*]] = phi i32 [ [[START]], %[[ENTRY]] ], [ [[IV_NEXT_PEEL:%.*]], %[[LOOP_LATCH:.*]] ]
+; BUDGET3-NEXT: [[C_PEEL:%.*]] = icmp eq i32 [[TMP3]], [[SUB]]
+; BUDGET3-NEXT: br i1 [[C_PEEL]], label %[[THEN:.*]], label %[[LOOP_LATCH]]
+; BUDGET3: [[THEN]]:
+; BUDGET3-NEXT: br label %[[LOOP_LATCH]]
+; BUDGET3: [[LOOP_LATCH]]:
+; BUDGET3-NEXT: [[IV_NEXT_PEEL]] = add nsw i32 [[TMP3]], 1
+; BUDGET3-NEXT: [[EC_PEEL:%.*]] = icmp eq i32 [[IV_NEXT_PEEL]], [[END]]
+; BUDGET3-NEXT: br i1 [[EC_PEEL]], label %[[EXIT:.*]], label %[[LOOP_HEADER]]
+; BUDGET3: [[EXIT]]:
+; BUDGET3-NEXT: ret i32 0
+;
+entry:
+ %sub = add i32 %end, -1
+ br label %loop.header
+
+loop.header:
+ %iv = phi i32 [ %start, %entry ], [ %iv.next, %loop.latch ]
+ %c = icmp eq i32 %iv, %sub
+ br i1 %c, label %then, label %loop.latch
+
+then:
+ br label %loop.latch
+
+loop.latch:
+ %iv.next = add nsw i32 %iv, 1
+ %ec = icmp eq i32 %iv.next, %end
+ br i1 %ec, label %exit, label %loop.header
+
+exit:
+ ret i32 0
+}
More information about the llvm-commits
mailing list