[llvm] d4abbcf - [LoopUnroll] Add test for unrollable non-latch multi-exit (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun May 23 01:53:19 PDT 2021


Author: Nikita Popov
Date: 2021-05-23T10:51:45+02:00
New Revision: d4abbcfb0d4aa57878c17940265035c787e3bec0

URL: https://github.com/llvm/llvm-project/commit/d4abbcfb0d4aa57878c17940265035c787e3bec0
DIFF: https://github.com/llvm/llvm-project/commit/d4abbcfb0d4aa57878c17940265035c787e3bec0.diff

LOG: [LoopUnroll] Add test for unrollable non-latch multi-exit (NFC)

This test case requires unrolling against a non-latch exit in
a multiple-exit loop with exiting latch. It's not covered by
exiting heuristics or the extension in D102635.

Added: 
    llvm/test/Transforms/LoopUnroll/full-unroll-non-latch-exit.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/LoopUnroll/full-unroll-non-latch-exit.ll b/llvm/test/Transforms/LoopUnroll/full-unroll-non-latch-exit.ll
new file mode 100644
index 0000000000000..9775a565068ee
--- /dev/null
+++ b/llvm/test/Transforms/LoopUnroll/full-unroll-non-latch-exit.ll
@@ -0,0 +1,68 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -loop-unroll %s | FileCheck %s
+
+; Full unrolling can be performed against the header exit here, but we have
+; both multiple exits and a latch exit. After full unrolling, this function
+; folds to ret i1 true.
+
+define i1 @test() {
+; CHECK-LABEL: @test(
+; CHECK-NEXT:  start:
+; CHECK-NEXT:    [[A1:%.*]] = alloca [2 x i64], align 8
+; CHECK-NEXT:    [[A2:%.*]] = alloca [2 x i64], align 8
+; CHECK-NEXT:    [[A1_0:%.*]] = getelementptr inbounds [2 x i64], [2 x i64]* [[A1]], i64 0, i64 0
+; CHECK-NEXT:    store i64 -5015437470765251660, i64* [[A1_0]], align 8
+; CHECK-NEXT:    [[A1_1:%.*]] = getelementptr inbounds [2 x i64], [2 x i64]* [[A1]], i64 0, i64 1
+; CHECK-NEXT:    store i64 -8661621401413125213, i64* [[A1_1]], align 8
+; CHECK-NEXT:    [[A2_0:%.*]] = getelementptr inbounds [2 x i64], [2 x i64]* [[A2]], i64 0, i64 0
+; CHECK-NEXT:    store i64 -5015437470765251660, i64* [[A2_0]], align 8
+; CHECK-NEXT:    [[A2_1:%.*]] = getelementptr inbounds [2 x i64], [2 x i64]* [[A2]], i64 0, i64 1
+; CHECK-NEXT:    store i64 -8661621401413125213, i64* [[A2_1]], align 8
+; CHECK-NEXT:    br label [[LOOP:%.*]]
+; CHECK:       loop:
+; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ 0, [[START:%.*]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
+; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 2
+; 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 [2 x i64], [2 x i64]* [[A1]], i64 0, i64 [[IV]]
+; CHECK-NEXT:    [[GEP2:%.*]] = getelementptr inbounds [2 x i64], [2 x i64]* [[A2]], i64 0, 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:
+  %a1 = alloca [2 x i64], align 8
+  %a2 = alloca [2 x i64], align 8
+  %a1.0 = getelementptr inbounds [2 x i64], [2 x i64]* %a1, i64 0, i64 0
+  store i64 -5015437470765251660, i64* %a1.0, align 8
+  %a1.1 = getelementptr inbounds [2 x i64], [2 x i64]* %a1, i64 0, i64 1
+  store i64 -8661621401413125213, i64* %a1.1, align 8
+  %a2.0 = getelementptr inbounds [2 x i64], [2 x i64]* %a2, i64 0, i64 0
+  store i64 -5015437470765251660, i64* %a2.0, align 8
+  %a2.1 = getelementptr inbounds [2 x i64], [2 x i64]* %a2, i64 0, i64 1
+  store i64 -8661621401413125213, i64* %a2.1, align 8
+  br label %loop
+
+loop:
+  %iv = phi i64 [ 0, %start ], [ %iv.next, %latch ]
+  %exitcond = icmp eq i64 %iv, 2
+  br i1 %exitcond, label %exit, label %latch
+
+latch:
+  %iv.next = add nuw nsw i64 %iv, 1
+  %gep1 = getelementptr inbounds [2 x i64], [2 x i64]* %a1, i64 0, i64 %iv
+  %gep2 = getelementptr inbounds [2 x i64], [2 x i64]* %a2, i64 0, 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