[llvm] 2cc7013 - [LoopPeel] Add tests where peeling turns invar accesses dereferenceable.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 8 02:19:10 PDT 2021
Author: Florian Hahn
Date: 2021-10-08T10:18:52+01:00
New Revision: 2cc7013b0ef4294d0dee460dff7aa03afce6bf6f
URL: https://github.com/llvm/llvm-project/commit/2cc7013b0ef4294d0dee460dff7aa03afce6bf6f
DIFF: https://github.com/llvm/llvm-project/commit/2cc7013b0ef4294d0dee460dff7aa03afce6bf6f.diff
LOG: [LoopPeel] Add tests where peeling turns invar accesses dereferenceable.
Precommit test cases for D108114.
Added:
llvm/test/Transforms/LoopUnroll/peel-to-turn-invariant-accesses-dereferenceable.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/LoopUnroll/peel-to-turn-invariant-accesses-dereferenceable.ll b/llvm/test/Transforms/LoopUnroll/peel-to-turn-invariant-accesses-dereferenceable.ll
new file mode 100644
index 0000000000000..c659550ddf92f
--- /dev/null
+++ b/llvm/test/Transforms/LoopUnroll/peel-to-turn-invariant-accesses-dereferenceable.ll
@@ -0,0 +1,526 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -loop-unroll -S %s | FileCheck %s
+
+declare void @foo()
+
+define i32 @peel_readonly_to_make_loads_derefenceable(i32* %ptr, i32 %N, i32* %inv, i1 %c.1) {
+; CHECK-LABEL: @peel_readonly_to_make_loads_derefenceable(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
+; CHECK: loop.header:
+; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
+; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: br i1 [[C_1:%.*]], label [[THEN:%.*]], label [[UNREACHABLE_EXIT:%.*]]
+; CHECK: then:
+; CHECK-NEXT: [[I:%.*]] = load i32, i32* [[INV:%.*]], align 4
+; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[I]], 2
+; CHECK-NEXT: br i1 [[C_2]], label [[LOOP_LATCH]], label [[UNREACHABLE_EXIT]]
+; CHECK: loop.latch:
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[IV]]
+; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[GEP]], align 4
+; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[LV]]
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
+; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[IV]], 1000
+; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_HEADER]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
+; CHECK: unreachable.exit:
+; CHECK-NEXT: call void @foo()
+; CHECK-NEXT: unreachable
+;
+entry:
+ br label %loop.header
+
+loop.header:
+ %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
+ %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ]
+ br i1 %c.1, label %then, label %unreachable.exit
+
+then:
+ %i = load i32, i32* %inv
+ %c.2 = icmp ult i32 %i, 2
+ br i1 %c.2, label %loop.latch, label %unreachable.exit
+
+loop.latch:
+ %gep = getelementptr i32, i32* %ptr, i32 %iv
+ %lv = load i32, i32* %gep
+ %sum.next = add i32 %sum, %lv
+ %iv.next = add nuw nsw i32 %iv, 1
+ %c.3 = icmp ult i32 %iv, 1000
+ br i1 %c.3, label %loop.header, label %exit
+
+exit:
+ ret i32 %sum.next
+
+unreachable.exit:
+ call void @foo()
+ unreachable
+}
+
+define i32 @do_not_peel_readonly_load_in_header(i32* %ptr, i32 %N, i32* %inv, i1 %c.1) {
+; CHECK-LABEL: @do_not_peel_readonly_load_in_header(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
+; CHECK: loop.header:
+; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
+; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: [[I:%.*]] = load i32, i32* [[INV:%.*]], align 4
+; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[I]], 2
+; CHECK-NEXT: br i1 [[C_2]], label [[THEN:%.*]], label [[UNREACHABLE_EXIT:%.*]]
+; CHECK: then:
+; CHECK-NEXT: br i1 [[C_1:%.*]], label [[LOOP_LATCH]], label [[UNREACHABLE_EXIT]]
+; CHECK: loop.latch:
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[IV]]
+; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[GEP]], align 4
+; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[LV]]
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
+; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[IV]], 1000
+; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_HEADER]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
+; CHECK: unreachable.exit:
+; CHECK-NEXT: call void @foo()
+; CHECK-NEXT: unreachable
+;
+entry:
+ br label %loop.header
+
+loop.header:
+ %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
+ %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ]
+ %i = load i32, i32* %inv
+ %c.2 = icmp ult i32 %i, 2
+ br i1 %c.2, label %then, label %unreachable.exit
+
+then:
+ br i1 %c.1, label %loop.latch, label %unreachable.exit
+
+loop.latch:
+ %gep = getelementptr i32, i32* %ptr, i32 %iv
+ %lv = load i32, i32* %gep
+ %sum.next = add i32 %sum, %lv
+ %iv.next = add nuw nsw i32 %iv, 1
+ %c.3 = icmp ult i32 %iv, 1000
+ br i1 %c.3, label %loop.header, label %exit
+
+exit:
+ ret i32 %sum.next
+
+unreachable.exit:
+ call void @foo()
+ unreachable
+}
+
+define i32 @do_not_peel_readonly_but_wont_turn_dereferenceable(i32* %ptr, i32 %N, i32 %x, i32* %inv) {
+; CHECK-LABEL: @do_not_peel_readonly_but_wont_turn_dereferenceable(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
+; CHECK: loop.header:
+; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
+; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[IV]], [[X:%.*]]
+; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK: then:
+; CHECK-NEXT: [[I:%.*]] = load i32, i32* [[INV:%.*]], align 4
+; CHECK-NEXT: [[C_2:%.*]] = icmp eq i32 [[I]], 20
+; CHECK-NEXT: br i1 [[C_2]], label [[UNREACHABLE_EXIT:%.*]], label [[LOOP_LATCH]]
+; CHECK: else:
+; CHECK-NEXT: br label [[LOOP_LATCH]]
+; CHECK: loop.latch:
+; CHECK-NEXT: [[P:%.*]] = phi i32 [ [[I]], [[THEN]] ], [ 0, [[ELSE]] ]
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[IV]]
+; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[GEP]], align 4
+; CHECK-NEXT: [[ADD_1:%.*]] = add i32 [[LV]], [[P]]
+; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[ADD_1]]
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
+; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[IV]], 1000
+; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_HEADER]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
+; CHECK: unreachable.exit:
+; CHECK-NEXT: call void @foo()
+; CHECK-NEXT: unreachable
+;
+entry:
+ br label %loop.header
+
+loop.header:
+ %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
+ %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ]
+ %c.1 = icmp eq i32 %iv, %x
+ br i1 %c.1, label %then, label %else
+
+then:
+ %i = load i32, i32* %inv
+ %c.2 = icmp eq i32 %i, 20
+ br i1 %c.2, label %unreachable.exit, label %loop.latch
+
+else:
+ br label %loop.latch
+
+loop.latch:
+ %p = phi i32 [ %i, %then ], [ 0, %else ]
+ %gep = getelementptr i32, i32* %ptr, i32 %iv
+ %lv = load i32, i32* %gep
+ %add.1 = add i32 %lv, %p
+ %sum.next = add i32 %sum, %add.1
+ %iv.next = add nuw nsw i32 %iv, 1
+ %c.3 = icmp ult i32 %iv, 1000
+ br i1 %c.3, label %loop.header, label %exit
+
+exit:
+ ret i32 %sum.next
+
+unreachable.exit:
+ call void @foo()
+ unreachable
+}
+
+define i32 @do_not_peel_write1(i32* %ptr, i32 %N, i32 %x, i32* %inv, i32* %dst, i1 %c.1) {
+; CHECK-LABEL: @do_not_peel_write1(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
+; CHECK: loop.header:
+; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
+; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: br i1 [[C_1:%.*]], label [[THEN:%.*]], label [[UNREACHABLE_EXIT:%.*]]
+; CHECK: then:
+; CHECK-NEXT: [[I:%.*]] = load i32, i32* [[INV:%.*]], align 4
+; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[I]], 2
+; CHECK-NEXT: br i1 [[C_2]], label [[LOOP_LATCH]], label [[UNREACHABLE_EXIT]]
+; CHECK: loop.latch:
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[IV]]
+; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[GEP]], align 4
+; CHECK-NEXT: store i32 [[LV]], i32* [[DST:%.*]], align 4
+; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[LV]]
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
+; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[IV]], 1000
+; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_HEADER]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
+; CHECK: unreachable.exit:
+; CHECK-NEXT: call void @foo()
+; CHECK-NEXT: unreachable
+;
+entry:
+ br label %loop.header
+
+loop.header:
+ %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
+ %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ]
+ br i1 %c.1, label %then, label %unreachable.exit
+
+then:
+ %i = load i32, i32* %inv
+ %c.2 = icmp ult i32 %i, 2
+ br i1 %c.2, label %loop.latch, label %unreachable.exit
+
+loop.latch:
+ %gep = getelementptr i32, i32* %ptr, i32 %iv
+ %lv = load i32, i32* %gep
+ store i32 %lv, i32* %dst
+ %sum.next = add i32 %sum, %lv
+ %iv.next = add nuw nsw i32 %iv, 1
+ %c.3 = icmp ult i32 %iv, 1000
+ br i1 %c.3, label %loop.header, label %exit
+
+exit:
+ ret i32 %sum.next
+
+unreachable.exit:
+ call void @foo()
+ unreachable
+}
+
+define i32 @do_not_peel_write2(i32* %ptr, i32 %N, i32* %inv, i32* %dst) {
+; CHECK-LABEL: @do_not_peel_write2(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
+; CHECK: loop.header:
+; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
+; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: [[I:%.*]] = load i32, i32* [[INV:%.*]], align 4
+; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[I]], 20
+; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK: then:
+; CHECK-NEXT: store i32 [[I]], i32* [[DST:%.*]], align 4
+; CHECK-NEXT: br label [[LOOP_LATCH]]
+; CHECK: else:
+; CHECK-NEXT: br label [[UNREACHABLE_EXIT:%.*]]
+; CHECK: loop.latch:
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[IV]]
+; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[GEP]], align 4
+; CHECK-NEXT: [[ADD_1:%.*]] = add i32 [[LV]], [[I]]
+; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[ADD_1]]
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
+; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[IV]], 1000
+; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_HEADER]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
+; CHECK: unreachable.exit:
+; CHECK-NEXT: call void @foo()
+; CHECK-NEXT: unreachable
+;
+entry:
+ br label %loop.header
+
+loop.header:
+ %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
+ %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ]
+ %i = load i32, i32* %inv
+ %c.1 = icmp eq i32 %i, 20
+ br i1 %c.1, label %then, label %else
+
+then:
+ store i32 %i, i32* %dst
+ br label %loop.latch
+
+else:
+ br label %unreachable.exit
+
+loop.latch:
+ %gep = getelementptr i32, i32* %ptr, i32 %iv
+ %lv = load i32, i32* %gep
+ %add.1 = add i32 %lv, %i
+ %sum.next = add i32 %sum, %add.1
+ %iv.next = add nuw nsw i32 %iv, 1
+ %c.3 = icmp ult i32 %iv, 1000
+ br i1 %c.3, label %loop.header, label %exit
+
+exit:
+ ret i32 %sum.next
+
+unreachable.exit:
+ call void @foo()
+ unreachable
+}
+
+declare i32 @llvm.experimental.deoptimize.i32(...)
+
+define i32 @do_not_peel_with_deopt_exit(i32* %ptr, i32 %N, i32* %inv, i1 %c.1) {
+; CHECK-LABEL: @do_not_peel_with_deopt_exit(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
+; CHECK: loop.header:
+; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
+; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: br i1 [[C_1:%.*]], label [[THEN:%.*]], label [[UNREACHABLE_EXIT:%.*]]
+; CHECK: then:
+; CHECK-NEXT: [[I:%.*]] = load i32, i32* [[INV:%.*]], align 4
+; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[I]], 2
+; CHECK-NEXT: br i1 [[C_2]], label [[LOOP_LATCH]], label [[UNREACHABLE_EXIT]]
+; CHECK: loop.latch:
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[IV]]
+; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[GEP]], align 4
+; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[LV]]
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
+; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[IV]], 1000
+; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_HEADER]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
+; CHECK: unreachable.exit:
+; CHECK-NEXT: [[SUM_LCSSA:%.*]] = phi i32 [ [[SUM]], [[THEN]] ], [ [[SUM]], [[LOOP_HEADER]] ]
+; CHECK-NEXT: [[RVAL:%.*]] = call i32 (...) @llvm.experimental.deoptimize.i32() [ "deopt"(i32 [[SUM_LCSSA]]) ]
+; CHECK-NEXT: ret i32 [[RVAL]]
+;
+entry:
+ br label %loop.header
+
+loop.header:
+ %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
+ %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ]
+ br i1 %c.1, label %then, label %unreachable.exit
+
+then:
+ %i = load i32, i32* %inv
+ %c.2 = icmp ult i32 %i, 2
+ br i1 %c.2, label %loop.latch, label %unreachable.exit
+
+loop.latch:
+ %gep = getelementptr i32, i32* %ptr, i32 %iv
+ %lv = load i32, i32* %gep
+ %sum.next = add i32 %sum, %lv
+ %iv.next = add nuw nsw i32 %iv, 1
+ %c.3 = icmp ult i32 %iv, 1000
+ br i1 %c.3, label %loop.header, label %exit
+
+exit:
+ ret i32 %sum.next
+
+unreachable.exit:
+ %rval = call i32(...) @llvm.experimental.deoptimize.i32() [ "deopt"(i32 %sum) ]
+ ret i32 %rval
+}
+
+define i32 @do_not_peel_when_header_exiting(i32* %ptr, i32 %N, i32* %inv) {
+; CHECK-LABEL: @do_not_peel_when_header_exiting(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
+; CHECK: loop.header:
+; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
+; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: [[C_1:%.*]] = icmp ult i32 [[IV]], 1000
+; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[EXIT:%.*]]
+; CHECK: then:
+; CHECK-NEXT: [[I:%.*]] = load i32, i32* [[INV:%.*]], align 4
+; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[I]], 2
+; CHECK-NEXT: br i1 [[C_2]], label [[LOOP_LATCH]], label [[UNREACHABLE_EXIT:%.*]]
+; CHECK: loop.latch:
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[IV]]
+; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[GEP]], align 4
+; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[LV]]
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
+; CHECK-NEXT: br label [[LOOP_HEADER]]
+; CHECK: exit:
+; CHECK-NEXT: [[SUM_LCSSA:%.*]] = phi i32 [ [[SUM]], [[LOOP_HEADER]] ]
+; CHECK-NEXT: ret i32 [[SUM_LCSSA]]
+; CHECK: unreachable.exit:
+; CHECK-NEXT: call void @foo()
+; CHECK-NEXT: unreachable
+;
+entry:
+ br label %loop.header
+
+loop.header:
+ %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
+ %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ]
+ %c.1 = icmp ult i32 %iv, 1000
+ br i1 %c.1, label %then, label %exit
+
+then:
+ %i = load i32, i32* %inv
+ %c.2 = icmp ult i32 %i, 2
+ br i1 %c.2, label %loop.latch, label %unreachable.exit
+
+loop.latch:
+ %gep = getelementptr i32, i32* %ptr, i32 %iv
+ %lv = load i32, i32* %gep
+ %sum.next = add i32 %sum, %lv
+ %iv.next = add nuw nsw i32 %iv, 1
+ br label %loop.header
+
+exit:
+ ret i32 %sum
+
+unreachable.exit:
+ call void @foo()
+ unreachable
+}
+
+define i32 @do_not_peel_readonly_to_make_loads_derefenceable_but_does_not_control_exit(i32* %ptr, i32 %N, i32* %inv, i1 %c.1, i32 %N.2) {
+; CHECK-LABEL: @do_not_peel_readonly_to_make_loads_derefenceable_but_does_not_control_exit(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
+; CHECK: loop.header:
+; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
+; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: br i1 [[C_1:%.*]], label [[THEN:%.*]], label [[UNREACHABLE_EXIT:%.*]]
+; CHECK: then:
+; CHECK-NEXT: [[I:%.*]] = load i32, i32* [[INV:%.*]], align 4
+; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[IV]], [[N_2:%.*]]
+; CHECK-NEXT: br i1 [[C_2]], label [[LOOP_LATCH]], label [[UNREACHABLE_EXIT]]
+; CHECK: loop.latch:
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[IV]]
+; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[GEP]], align 4
+; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[LV]]
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
+; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[IV]], 1000
+; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_HEADER]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
+; CHECK: unreachable.exit:
+; CHECK-NEXT: call void @foo()
+; CHECK-NEXT: unreachable
+;
+entry:
+ br label %loop.header
+
+loop.header:
+ %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
+ %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ]
+ br i1 %c.1, label %then, label %unreachable.exit
+
+then:
+ %i = load i32, i32* %inv
+ %c.2 = icmp ult i32 %iv, %N.2
+ br i1 %c.2, label %loop.latch, label %unreachable.exit
+
+loop.latch:
+ %gep = getelementptr i32, i32* %ptr, i32 %iv
+ %lv = load i32, i32* %gep
+ %sum.next = add i32 %sum, %lv
+ %iv.next = add nuw nsw i32 %iv, 1
+ %c.3 = icmp ult i32 %iv, 1000
+ br i1 %c.3, label %loop.header, label %exit
+
+exit:
+ ret i32 %sum.next
+
+unreachable.exit:
+ call void @foo()
+ unreachable
+}
+
+ at glob = global i32 10
+
+define i32 @do_not_peel_readonly_but_already_deref_glob(i32* %ptr, i32 %N, i1 %c.1) {
+; CHECK-LABEL: @do_not_peel_readonly_but_already_deref_glob(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
+; CHECK: loop.header:
+; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
+; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: br i1 [[C_1:%.*]], label [[THEN:%.*]], label [[UNREACHABLE_EXIT:%.*]]
+; CHECK: then:
+; CHECK-NEXT: [[I:%.*]] = load i32, i32* @glob, align 4
+; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[I]], 2
+; CHECK-NEXT: br i1 [[C_2]], label [[LOOP_LATCH]], label [[UNREACHABLE_EXIT]]
+; CHECK: loop.latch:
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[IV]]
+; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[GEP]], align 4
+; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[LV]]
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
+; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[IV]], 1000
+; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_HEADER]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[LOOP_LATCH]] ]
+; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
+; CHECK: unreachable.exit:
+; CHECK-NEXT: call void @foo()
+; CHECK-NEXT: unreachable
+;
+entry:
+ br label %loop.header
+
+loop.header:
+ %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
+ %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ]
+ br i1 %c.1, label %then, label %unreachable.exit
+
+then:
+ %i = load i32, i32* @glob
+ %c.2 = icmp ult i32 %i, 2
+ br i1 %c.2, label %loop.latch, label %unreachable.exit
+
+loop.latch:
+ %gep = getelementptr i32, i32* %ptr, i32 %iv
+ %lv = load i32, i32* %gep
+ %sum.next = add i32 %sum, %lv
+ %iv.next = add nuw nsw i32 %iv, 1
+ %c.3 = icmp ult i32 %iv, 1000
+ br i1 %c.3, label %loop.header, label %exit
+
+exit:
+ ret i32 %sum.next
+
+unreachable.exit:
+ call void @foo()
+ unreachable
+}
More information about the llvm-commits
mailing list