[LSR] Add test case which shows additional LSR with D144050.
authorFlorian Hahn <flo@fhahn.com>
Thu, 16 Feb 2023 16:12:07 +0000 (16:12 +0000)
committerFlorian Hahn <flo@fhahn.com>
Thu, 16 Feb 2023 16:12:07 +0000 (16:12 +0000)
llvm/test/Transforms/LoopStrengthReduce/lsr-rewrite-to-add-one.ll [new file with mode: 0644]

diff --git a/llvm/test/Transforms/LoopStrengthReduce/lsr-rewrite-to-add-one.ll b/llvm/test/Transforms/LoopStrengthReduce/lsr-rewrite-to-add-one.ll
new file mode 100644 (file)
index 0000000..ecbd347
--- /dev/null
@@ -0,0 +1,51 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=loop-reduce -S %s | FileCheck %s
+
+target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7"
+
+define i32 @test(i1 %c.1, ptr %src) {
+; CHECK-LABEL: @test(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label [[LOOP_HEADER:%.*]]
+; CHECK:       loop.header:
+; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
+; CHECK-NEXT:    br i1 [[C_1:%.*]], label [[LOOP_LATCH]], label [[LOOP_THEN:%.*]]
+; CHECK:       loop.then:
+; CHECK-NEXT:    [[L:%.*]] = load i32, ptr [[SRC:%.*]], align 4
+; CHECK-NEXT:    [[C_2:%.*]] = icmp eq i32 [[L]], 0
+; CHECK-NEXT:    br label [[LOOP_LATCH]]
+; CHECK:       loop.latch:
+; CHECK-NEXT:    [[P:%.*]] = phi i1 [ [[C_2]], [[LOOP_THEN]] ], [ false, [[LOOP_HEADER]] ]
+; CHECK-NEXT:    [[T:%.*]] = icmp sgt i32 [[IV]], -1050
+; CHECK-NEXT:    [[OR:%.*]] = or i1 [[P]], [[T]]
+; CHECK-NEXT:    [[ZEXT_OR:%.*]] = zext i1 [[OR]] to i32
+; CHECK-NEXT:    [[IV_NEXT]] = add i32 [[IV]], [[ZEXT_OR]]
+; CHECK-NEXT:    [[LOOP_HEADER_TERMCOND:%.*]] = icmp sgt i32 [[IV]], -1050
+; CHECK-NEXT:    br i1 [[LOOP_HEADER_TERMCOND]], label [[LOOP_HEADER]], label [[EXIT:%.*]]
+; CHECK:       exit:
+; CHECK-NEXT:    [[ZEXT_OR_LCSSA:%.*]] = phi i32 [ [[ZEXT_OR]], [[LOOP_LATCH]] ]
+; CHECK-NEXT:    ret i32 [[ZEXT_OR_LCSSA]]
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
+  br i1 %c.1, label %loop.latch, label %loop.then
+
+loop.then:
+  %l = load i32, ptr %src
+  %c.2 = icmp eq i32 %l, 0
+  br label %loop.latch
+
+loop.latch:
+  %p = phi i1 [ %c.2, %loop.then ], [ 0, %loop.header ]
+  %t = icmp sgt i32 %iv, -1050
+  %or = or i1 %p, %t
+  %zext.or = zext i1 %or to i32
+  %iv.next = add i32 %iv, %zext.or
+  br i1 %t, label %loop.header, label %exit
+
+exit:
+  ret i32 %zext.or
+}