[llvm] fc5a579 - [IRCE][Tests] Add tests with range checks in the form of 'iv + offset vs limit'
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 3 02:39:04 PDT 2023
Author: aleks-tmb
Date: 2023-07-02T08:23:44+02:00
New Revision: fc5a5794ab5682f8b2052639fe5845cc5e7da593
URL: https://github.com/llvm/llvm-project/commit/fc5a5794ab5682f8b2052639fe5845cc5e7da593
DIFF: https://github.com/llvm/llvm-project/commit/fc5a5794ab5682f8b2052639fe5845cc5e7da593.diff
LOG: [IRCE][Tests] Add tests with range checks in the form of 'iv + offset vs limit'
Added tests on 3 types of range checks which are not supported by IRCE now:
* N - IV >= limit
* IV - N <= limit
* IV + N <= limit
Reviewed By: skatkov
Differential Revision: https://reviews.llvm.org/D154062
Added:
llvm/test/Transforms/IRCE/iv-plus-offset-range-check.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/IRCE/iv-plus-offset-range-check.ll b/llvm/test/Transforms/IRCE/iv-plus-offset-range-check.ll
new file mode 100644
index 00000000000000..cd076d0c10d964
--- /dev/null
+++ b/llvm/test/Transforms/IRCE/iv-plus-offset-range-check.ll
@@ -0,0 +1,161 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -verify-loop-info -passes=irce -S < %s 2>&1 | FileCheck %s
+
+; IV = 0; IV <s limit; IV += 1;
+; Check(N - IV >= 2)
+; TODO: IRCE is allowed
+define i8 @test1(i8 %limit, i8 %n) {
+; CHECK-LABEL: define i8 @test1
+; CHECK-SAME: (i8 [[LIMIT:%.*]], i8 [[N:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[PRECHECK:%.*]] = icmp sgt i8 [[LIMIT]], 0
+; CHECK-NEXT: br i1 [[PRECHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
+; CHECK: loop.preheader:
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[IDX:%.*]] = phi i8 [ [[IDX_NEXT:%.*]], [[INBOUNDS:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
+; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[N]], [[IDX]]
+; CHECK-NEXT: [[CHECK:%.*]] = icmp sge i8 [[SUB]], 2
+; CHECK-NEXT: br i1 [[CHECK]], label [[INBOUNDS]], label [[OUT_OF_BOUNDS:%.*]]
+; CHECK: inbounds:
+; CHECK-NEXT: [[IDX_NEXT]] = add nuw i8 [[IDX]], 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[IDX_NEXT]], [[LIMIT]]
+; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
+; CHECK: exit.loopexit:
+; CHECK-NEXT: [[IDX_LCSSA1:%.*]] = phi i8 [ [[IDX]], [[INBOUNDS]] ]
+; CHECK-NEXT: br label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: [[RES:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IDX_LCSSA1]], [[EXIT_LOOPEXIT]] ]
+; CHECK-NEXT: ret i8 [[RES]]
+; CHECK: out_of_bounds:
+; CHECK-NEXT: [[IDX_LCSSA:%.*]] = phi i8 [ [[IDX]], [[LOOP]] ]
+; CHECK-NEXT: ret i8 [[IDX_LCSSA]]
+;
+entry:
+ %precheck = icmp sgt i8 %limit, 0
+ br i1 %precheck, label %loop, label %exit
+
+loop:
+ %idx = phi i8 [ %idx.next, %inbounds ], [ 0, %entry ]
+ %sub = sub i8 %n, %idx
+ %check = icmp sge i8 %sub, 2
+ br i1 %check, label %inbounds, label %out_of_bounds
+
+inbounds:
+ %idx.next = add nuw i8 %idx, 1
+ %cmp = icmp slt i8 %idx.next, %limit
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ %res = phi i8 [ 0, %entry ], [ %idx, %inbounds ]
+ ret i8 %res
+
+out_of_bounds:
+ ret i8 %idx;
+}
+
+; IV = 0; IV <s limit; IV += 1;
+; Check(IV - N <= -2)
+; TODO: IRCE is allowed
+define i8 @test2(i8 %limit, i8 %n) {
+; CHECK-LABEL: define i8 @test2
+; CHECK-SAME: (i8 [[LIMIT:%.*]], i8 [[N:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[PRECHECK:%.*]] = icmp sgt i8 [[LIMIT]], 0
+; CHECK-NEXT: br i1 [[PRECHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
+; CHECK: loop.preheader:
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[IDX:%.*]] = phi i8 [ [[IDX_NEXT:%.*]], [[INBOUNDS:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
+; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[IDX]], [[N]]
+; CHECK-NEXT: [[CHECK:%.*]] = icmp sle i8 [[SUB]], -2
+; CHECK-NEXT: br i1 [[CHECK]], label [[INBOUNDS]], label [[OUT_OF_BOUNDS:%.*]]
+; CHECK: inbounds:
+; CHECK-NEXT: [[IDX_NEXT]] = add nuw i8 [[IDX]], 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[IDX_NEXT]], [[LIMIT]]
+; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
+; CHECK: exit.loopexit:
+; CHECK-NEXT: [[IDX_LCSSA1:%.*]] = phi i8 [ [[IDX]], [[INBOUNDS]] ]
+; CHECK-NEXT: br label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: [[RES:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IDX_LCSSA1]], [[EXIT_LOOPEXIT]] ]
+; CHECK-NEXT: ret i8 [[RES]]
+; CHECK: out_of_bounds:
+; CHECK-NEXT: [[IDX_LCSSA:%.*]] = phi i8 [ [[IDX]], [[LOOP]] ]
+; CHECK-NEXT: ret i8 [[IDX_LCSSA]]
+;
+entry:
+ %precheck = icmp sgt i8 %limit, 0
+ br i1 %precheck, label %loop, label %exit
+
+loop:
+ %idx = phi i8 [ %idx.next, %inbounds ], [ 0, %entry ]
+ %sub = sub i8 %idx, %n
+ %check = icmp sle i8 %sub, -2
+ br i1 %check, label %inbounds, label %out_of_bounds
+
+inbounds:
+ %idx.next = add nuw i8 %idx, 1
+ %cmp = icmp slt i8 %idx.next, %limit
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ %res = phi i8 [ 0, %entry ], [ %idx, %inbounds ]
+ ret i8 %res
+
+out_of_bounds:
+ ret i8 %idx;
+}
+
+; IV = 0; IV <s limit; IV += 1;
+; Check(IV + 2 <= N)
+; TODO: IRCE is allowed
+define i8 @test3(i8 %limit, i8 %n) {
+; CHECK-LABEL: define i8 @test3
+; CHECK-SAME: (i8 [[LIMIT:%.*]], i8 [[N:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[PRECHECK:%.*]] = icmp sgt i8 [[LIMIT]], 0
+; CHECK-NEXT: br i1 [[PRECHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
+; CHECK: loop.preheader:
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[IDX:%.*]] = phi i8 [ [[IDX_NEXT:%.*]], [[INBOUNDS:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
+; CHECK-NEXT: [[ADD:%.*]] = add i8 [[IDX]], 2
+; CHECK-NEXT: [[CHECK:%.*]] = icmp sle i8 [[ADD]], [[N]]
+; CHECK-NEXT: br i1 [[CHECK]], label [[INBOUNDS]], label [[OUT_OF_BOUNDS:%.*]]
+; CHECK: inbounds:
+; CHECK-NEXT: [[IDX_NEXT]] = add nuw i8 [[IDX]], 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[IDX_NEXT]], [[LIMIT]]
+; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
+; CHECK: exit.loopexit:
+; CHECK-NEXT: [[IDX_LCSSA1:%.*]] = phi i8 [ [[IDX]], [[INBOUNDS]] ]
+; CHECK-NEXT: br label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: [[RES:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IDX_LCSSA1]], [[EXIT_LOOPEXIT]] ]
+; CHECK-NEXT: ret i8 [[RES]]
+; CHECK: out_of_bounds:
+; CHECK-NEXT: [[IDX_LCSSA:%.*]] = phi i8 [ [[IDX]], [[LOOP]] ]
+; CHECK-NEXT: ret i8 [[IDX_LCSSA]]
+;
+entry:
+ %precheck = icmp sgt i8 %limit, 0
+ br i1 %precheck, label %loop, label %exit
+
+loop:
+ %idx = phi i8 [ %idx.next, %inbounds ], [ 0, %entry ]
+ %add = add i8 %idx, 2
+ %check = icmp sle i8 %add, %n
+ br i1 %check, label %inbounds, label %out_of_bounds
+
+inbounds:
+ %idx.next = add nuw i8 %idx, 1
+ %cmp = icmp slt i8 %idx.next, %limit
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ %res = phi i8 [ 0, %entry ], [ %idx, %inbounds ]
+ ret i8 %res
+
+out_of_bounds:
+ ret i8 %idx;
+}
More information about the llvm-commits
mailing list