[LoopRotate] Precommit test for prepare-for-lto handling.
authorFlorian Hahn <flo@fhahn.com>
Mon, 18 Jan 2021 15:18:17 +0000 (15:18 +0000)
committerFlorian Hahn <flo@fhahn.com>
Mon, 18 Jan 2021 15:24:18 +0000 (15:24 +0000)
Precommit test for D94232.

llvm/test/Transforms/LoopRotate/call-prepare-for-lto.ll [new file with mode: 0644]

diff --git a/llvm/test/Transforms/LoopRotate/call-prepare-for-lto.ll b/llvm/test/Transforms/LoopRotate/call-prepare-for-lto.ll
new file mode 100644 (file)
index 0000000..dff7339
--- /dev/null
@@ -0,0 +1,36 @@
+; RUN: opt -S -loop-rotate < %s | FileCheck --check-prefix=FULL %s
+; RUN: opt -S -passes='require<targetir>,require<assumptions>,loop(loop-rotate)' < %s | FileCheck --check-prefix=FULL %s
+
+; Test case to make sure loop-rotate avoids rotating during the prepare-for-lto
+; stage, when the header contains a call which may be inlined during the LTO stage.
+define void @test_prepare_for_lto() {
+; FULL-LABEL: @test_prepare_for_lto(
+; FULL-NEXT:  entry:
+; FULL-NEXT:    %array = alloca [20 x i32], align 16
+; FULL-NEXT:    %arrayidx = getelementptr inbounds [20 x i32], [20 x i32]* %array, i64 0, i64 0
+; FULL-NEXT:    call void @may_be_inlined()
+; FULL-NEXT:    br label %for.body
+;
+entry:
+  %array = alloca [20 x i32], align 16
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.body, %entry
+  %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+  %cmp = icmp slt i32 %i.0, 100
+  %arrayidx = getelementptr inbounds [20 x i32], [20 x i32]* %array, i64 0, i64 0
+  call void @may_be_inlined()
+  br i1 %cmp, label %for.body, label %for.end
+
+for.body:                                         ; preds = %for.cond
+  store i32 0, i32* %arrayidx, align 16
+  %inc = add nsw i32 %i.0, 1
+  br label %for.cond
+
+for.end:                                          ; preds = %for.cond
+  ret void
+}
+
+define void @may_be_inlined() {
+  ret void
+}