[llvm] 15b1084 - [LoopUnroll] Add test for partial unrolling again non-latch exit (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun May 23 14:10:42 PDT 2021
Author: Nikita Popov
Date: 2021-05-23T23:10:23+02:00
New Revision: 15b108442fc843d509875ef77c4750ebbc8d4cca
URL: https://github.com/llvm/llvm-project/commit/15b108442fc843d509875ef77c4750ebbc8d4cca
DIFF: https://github.com/llvm/llvm-project/commit/15b108442fc843d509875ef77c4750ebbc8d4cca.diff
LOG: [LoopUnroll] Add test for partial unrolling again non-latch exit (NFC)
This test case would get miscompiled by the current version of
D102982, because unrolling does not respect the PreserveCondBr
flag for partial unrolling.
Added:
llvm/test/Transforms/LoopUnroll/partial-unroll-non-latch-exit.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/LoopUnroll/partial-unroll-non-latch-exit.ll b/llvm/test/Transforms/LoopUnroll/partial-unroll-non-latch-exit.ll
new file mode 100644
index 000000000000..aebcc3a350fd
--- /dev/null
+++ b/llvm/test/Transforms/LoopUnroll/partial-unroll-non-latch-exit.ll
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -loop-unroll -unroll-allow-partial %s | FileCheck %s
+
+; This is a variant on full-unroll-non-latch-exit.ll for partial unrolling.
+; This test is primarily interested in making sure that latches are not
+; folded incorrectly, not that a transform occurs.
+
+define i1 @test(i64* %a1, i64* %a2) {
+; CHECK-LABEL: @test(
+; CHECK-NEXT: start:
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[START:%.*]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
+; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 24
+; CHECK-NEXT: br i1 [[EXITCOND]], label [[EXIT:%.*]], label [[LATCH]]
+; CHECK: latch:
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i64, i64* [[A1:%.*]], i64 [[IV]]
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i64, i64* [[A2:%.*]], i64 [[IV]]
+; CHECK-NEXT: [[LOAD1:%.*]] = load i64, i64* [[GEP1]], align 8
+; CHECK-NEXT: [[LOAD2:%.*]] = load i64, i64* [[GEP2]], align 8
+; CHECK-NEXT: [[EXITCOND2:%.*]] = icmp eq i64 [[LOAD1]], [[LOAD2]]
+; CHECK-NEXT: br i1 [[EXITCOND2]], label [[LOOP]], label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: [[EXIT_VAL:%.*]] = phi i1 [ false, [[LATCH]] ], [ true, [[LOOP]] ]
+; CHECK-NEXT: ret i1 [[EXIT_VAL]]
+;
+start:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ 0, %start ], [ %iv.next, %latch ]
+ %exitcond = icmp eq i64 %iv, 24
+ br i1 %exitcond, label %exit, label %latch
+
+latch:
+ %iv.next = add nuw nsw i64 %iv, 1
+ %gep1 = getelementptr inbounds i64, i64* %a1, i64 %iv
+ %gep2 = getelementptr inbounds i64, i64* %a2, i64 %iv
+ %load1 = load i64, i64* %gep1, align 8
+ %load2 = load i64, i64* %gep2, align 8
+ %exitcond2 = icmp eq i64 %load1, %load2
+ br i1 %exitcond2, label %loop, label %exit
+
+exit:
+ %exit.val = phi i1 [ false, %latch ], [ true, %loop ]
+ ret i1 %exit.val
+}
More information about the llvm-commits
mailing list