1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -correlated-propagation -S | FileCheck %s
3 ; RUN: opt < %s -passes="correlated-propagation" -S | FileCheck %s
5 define i8* @simplify_phi_common_value_op0(i8* %ptr, i32* %b) {
6 ; CHECK-LABEL: @simplify_phi_common_value_op0(
8 ; CHECK-NEXT: [[ISNULL:%.*]] = icmp eq i8* [[PTR:%.*]], null
9 ; CHECK-NEXT: br i1 [[ISNULL]], label [[RETURN:%.*]], label [[ELSE:%.*]]
11 ; CHECK-NEXT: [[LB:%.*]] = load i32, i32* [[B:%.*]]
12 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[LB]], 1
13 ; CHECK-NEXT: store i32 [[ADD]], i32* [[B]]
14 ; CHECK-NEXT: br label [[RETURN]]
16 ; CHECK-NEXT: ret i8* [[PTR]]
19 %isnull = icmp eq i8* %ptr, null
20 br i1 %isnull, label %return, label %else
23 %lb = load i32, i32* %b
24 %add = add nsw i32 %lb, 1
25 store i32 %add, i32* %b
29 %r = phi i8* [ %ptr, %else ], [ null, %entry ]
33 define i8* @simplify_phi_common_value_op1(i8* %ptr, i32* %b) {
34 ; CHECK-LABEL: @simplify_phi_common_value_op1(
36 ; CHECK-NEXT: [[ISNULL:%.*]] = icmp eq i8* [[PTR:%.*]], null
37 ; CHECK-NEXT: br i1 [[ISNULL]], label [[RETURN:%.*]], label [[ELSE:%.*]]
39 ; CHECK-NEXT: [[LB:%.*]] = load i32, i32* [[B:%.*]]
40 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[LB]], 1
41 ; CHECK-NEXT: store i32 [[ADD]], i32* [[B]]
42 ; CHECK-NEXT: br label [[RETURN]]
44 ; CHECK-NEXT: ret i8* [[PTR]]
47 %isnull = icmp eq i8* %ptr, null
48 br i1 %isnull, label %return, label %else
51 %lb = load i32, i32* %b
53 store i32 %add, i32* %b
57 %r = phi i8* [ null, %entry], [ %ptr, %else ]
61 define i8 @simplify_phi_multiple_constants(i8 %x, i32* %b) {
62 ; CHECK-LABEL: @simplify_phi_multiple_constants(
64 ; CHECK-NEXT: [[IS0:%.*]] = icmp eq i8 [[X:%.*]], 0
65 ; CHECK-NEXT: br i1 [[IS0]], label [[RETURN:%.*]], label [[ELSE1:%.*]]
67 ; CHECK-NEXT: [[IS42:%.*]] = icmp eq i8 [[X]], 42
68 ; CHECK-NEXT: br i1 [[IS42]], label [[RETURN]], label [[ELSE2:%.*]]
70 ; CHECK-NEXT: [[LB:%.*]] = load i32, i32* [[B:%.*]]
71 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[LB]], 1
72 ; CHECK-NEXT: store i32 [[ADD]], i32* [[B]]
73 ; CHECK-NEXT: br label [[RETURN]]
75 ; CHECK-NEXT: ret i8 [[X]]
78 %is0 = icmp eq i8 %x, 0
79 br i1 %is0, label %return, label %else1
82 %is42 = icmp eq i8 %x, 42
83 br i1 %is42, label %return, label %else2
86 %lb = load i32, i32* %b
88 store i32 %add, i32* %b
92 %r = phi i8 [ 0, %entry], [ %x, %else2 ], [ 42, %else1 ]
96 define i8* @simplify_phi_common_value_from_instruction(i8* %ptr_op, i32* %b, i32 %i) {
97 ; CHECK-LABEL: @simplify_phi_common_value_from_instruction(
99 ; CHECK-NEXT: [[PTR:%.*]] = getelementptr i8, i8* [[PTR_OP:%.*]], i32 [[I:%.*]]
100 ; CHECK-NEXT: [[ISNULL:%.*]] = icmp eq i8* [[PTR]], null
101 ; CHECK-NEXT: br i1 [[ISNULL]], label [[RETURN:%.*]], label [[ELSE:%.*]]
103 ; CHECK-NEXT: [[LB:%.*]] = load i32, i32* [[B:%.*]]
104 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[LB]], 1
105 ; CHECK-NEXT: store i32 [[ADD]], i32* [[B]]
106 ; CHECK-NEXT: br label [[RETURN]]
108 ; CHECK-NEXT: ret i8* [[PTR]]
111 %ptr = getelementptr i8, i8* %ptr_op, i32 %i
112 %isnull = icmp eq i8* %ptr, null
113 br i1 %isnull, label %return, label %else
116 %lb = load i32, i32* %b
117 %add = add nsw i32 %lb, 1
118 store i32 %add, i32* %b
122 %r = phi i8* [ %ptr, %else ], [ null, %entry ]