[llvm] 65d09bc - [Test] Add two more tests on PRE with guards
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 8 23:20:47 PDT 2021
Author: Max Kazantsev
Date: 2021-04-09T13:20:23+07:00
New Revision: 65d09bcb078d48edc5e10c6e4842966833cd15ef
URL: https://github.com/llvm/llvm-project/commit/65d09bcb078d48edc5e10c6e4842966833cd15ef
DIFF: https://github.com/llvm/llvm-project/commit/65d09bcb078d48edc5e10c6e4842966833cd15ef.diff
LOG: [Test] Add two more tests on PRE with guards
Added:
Modified:
llvm/test/Transforms/GVN/PRE/pre-loop-load.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/GVN/PRE/pre-loop-load.ll b/llvm/test/Transforms/GVN/PRE/pre-loop-load.ll
index 39f551df6f26..f1433cfc2263 100644
--- a/llvm/test/Transforms/GVN/PRE/pre-loop-load.ll
+++ b/llvm/test/Transforms/GVN/PRE/pre-loop-load.ll
@@ -633,3 +633,105 @@ exit:
cold_exit:
ret i32 -1
}
+
+declare void @llvm.experimental.guard(i1, ...)
+
+define i32 @test_guard_1(i32* %p, i32 %g) {
+; CHECK-LABEL: @test_guard_1(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
+; CHECK-NEXT: [[GUARD_COND:%.*]] = icmp ne i32 [[IV]], [[G:%.*]]
+; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[GUARD_COND]]) [ "deopt"() ]
+; CHECK-NEXT: [[X:%.*]] = load i32, i32* [[P:%.*]], align 4
+; CHECK-NEXT: [[COND:%.*]] = icmp ult i32 [[X]], 100
+; CHECK-NEXT: br i1 [[COND]], label [[HOT_PATH:%.*]], label [[COLD_PATH:%.*]]
+; CHECK: hot_path:
+; CHECK-NEXT: br label [[BACKEDGE]]
+; CHECK: cold_path:
+; CHECK-NEXT: call void @side_effect()
+; CHECK-NEXT: br label [[BACKEDGE]]
+; CHECK: backedge:
+; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], [[X]]
+; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ult i32 [[IV_NEXT]], 1000
+; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: ret i32 [[X]]
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [ 0, %entry], [%iv.next, %backedge]
+ %guard_cond = icmp ne i32 %iv, %g
+ call void(i1, ...) @llvm.experimental.guard(i1 %guard_cond) [ "deopt"() ]
+ %x = load i32, i32* %p
+ %cond = icmp ult i32 %x, 100
+ br i1 %cond, label %hot_path, label %cold_path
+
+hot_path:
+ br label %backedge
+
+cold_path:
+ call void @side_effect()
+ br label %backedge
+
+backedge:
+ %iv.next = add i32 %iv, %x
+ %loop.cond = icmp ult i32 %iv.next, 1000
+ br i1 %loop.cond, label %loop, label %exit
+
+exit:
+ ret i32 %x
+}
+
+define i32 @test_guard_2(i32* %p, i32 %g) {
+; CHECK-LABEL: @test_guard_2(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
+; CHECK-NEXT: [[GUARD_COND:%.*]] = icmp ne i32 [[IV]], [[G:%.*]]
+; CHECK-NEXT: [[X:%.*]] = load i32, i32* [[P:%.*]], align 4
+; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[GUARD_COND]]) [ "deopt"() ]
+; CHECK-NEXT: [[COND:%.*]] = icmp ult i32 [[X]], 100
+; CHECK-NEXT: br i1 [[COND]], label [[HOT_PATH:%.*]], label [[COLD_PATH:%.*]]
+; CHECK: hot_path:
+; CHECK-NEXT: br label [[BACKEDGE]]
+; CHECK: cold_path:
+; CHECK-NEXT: call void @side_effect()
+; CHECK-NEXT: br label [[BACKEDGE]]
+; CHECK: backedge:
+; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], [[X]]
+; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ult i32 [[IV_NEXT]], 1000
+; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: ret i32 [[X]]
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [ 0, %entry], [%iv.next, %backedge]
+ %guard_cond = icmp ne i32 %iv, %g
+ %x = load i32, i32* %p
+ call void(i1, ...) @llvm.experimental.guard(i1 %guard_cond) [ "deopt"() ]
+ %cond = icmp ult i32 %x, 100
+ br i1 %cond, label %hot_path, label %cold_path
+
+hot_path:
+ br label %backedge
+
+cold_path:
+ call void @side_effect()
+ br label %backedge
+
+backedge:
+ %iv.next = add i32 %iv, %x
+ %loop.cond = icmp ult i32 %iv.next, 1000
+ br i1 %loop.cond, label %loop, label %exit
+
+exit:
+ ret i32 %x
+}
More information about the llvm-commits
mailing list