1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -correlated-propagation -S | FileCheck %s
; RUN: opt < %s -passes="correlated-propagation" -S | FileCheck %s
define i8* @simplify_phi_common_value_op0(i8* %ptr, i32* %b) {
; CHECK-LABEL: @simplify_phi_common_value_op0(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[ISNULL:%.*]] = icmp eq i8* [[PTR:%.*]], null
; CHECK-NEXT: br i1 [[ISNULL]], label [[RETURN:%.*]], label [[ELSE:%.*]]
; CHECK: else:
; CHECK-NEXT: [[LB:%.*]] = load i32, i32* [[B:%.*]], align 4
; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[LB]], 1
; CHECK-NEXT: store i32 [[ADD]], i32* [[B]]
; CHECK-NEXT: br label [[RETURN]]
; CHECK: return:
; CHECK-NEXT: ret i8* [[PTR]]
;
entry:
%isnull = icmp eq i8* %ptr, null
br i1 %isnull, label %return, label %else
else:
%lb = load i32, i32* %b
%add = add nsw i32 %lb, 1
store i32 %add, i32* %b
br label %return
return:
%r = phi i8* [ %ptr, %else ], [ null, %entry ]
ret i8* %r
}
define i8* @simplify_phi_common_value_op1(i8* %ptr, i32* %b) {
; CHECK-LABEL: @simplify_phi_common_value_op1(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[ISNULL:%.*]] = icmp eq i8* [[PTR:%.*]], null
; CHECK-NEXT: br i1 [[ISNULL]], label [[RETURN:%.*]], label [[ELSE:%.*]]
; CHECK: else:
; CHECK-NEXT: [[LB:%.*]] = load i32, i32* [[B:%.*]], align 4
; CHECK-NEXT: [[ADD:%.*]] = add i32 [[LB]], 1
; CHECK-NEXT: store i32 [[ADD]], i32* [[B]]
; CHECK-NEXT: br label [[RETURN]]
; CHECK: return:
; CHECK-NEXT: ret i8* [[PTR]]
;
entry:
%isnull = icmp eq i8* %ptr, null
br i1 %isnull, label %return, label %else
else:
%lb = load i32, i32* %b
%add = add i32 %lb, 1
store i32 %add, i32* %b
br label %return
return:
%r = phi i8* [ null, %entry], [ %ptr, %else ]
ret i8* %r
}
define i8 @simplify_phi_multiple_constants(i8 %x, i32* %b) {
; CHECK-LABEL: @simplify_phi_multiple_constants(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[IS0:%.*]] = icmp eq i8 [[X:%.*]], 0
; CHECK-NEXT: br i1 [[IS0]], label [[RETURN:%.*]], label [[ELSE1:%.*]]
; CHECK: else1:
; CHECK-NEXT: [[IS42:%.*]] = icmp eq i8 [[X]], 42
; CHECK-NEXT: br i1 [[IS42]], label [[RETURN]], label [[ELSE2:%.*]]
; CHECK: else2:
; CHECK-NEXT: [[LB:%.*]] = load i32, i32* [[B:%.*]], align 4
; CHECK-NEXT: [[ADD:%.*]] = add i32 [[LB]], 1
; CHECK-NEXT: store i32 [[ADD]], i32* [[B]]
; CHECK-NEXT: br label [[RETURN]]
; CHECK: return:
; CHECK-NEXT: ret i8 [[X]]
;
entry:
%is0 = icmp eq i8 %x, 0
br i1 %is0, label %return, label %else1
else1:
%is42 = icmp eq i8 %x, 42
br i1 %is42, label %return, label %else2
else2:
%lb = load i32, i32* %b
%add = add i32 %lb, 1
store i32 %add, i32* %b
br label %return
return:
%r = phi i8 [ 0, %entry], [ %x, %else2 ], [ 42, %else1 ]
ret i8 %r
}
define i8* @simplify_phi_common_value_from_instruction(i8* %ptr_op, i32* %b, i32 %i) {
; CHECK-LABEL: @simplify_phi_common_value_from_instruction(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[PTR:%.*]] = getelementptr i8, i8* [[PTR_OP:%.*]], i32 [[I:%.*]]
; CHECK-NEXT: [[ISNULL:%.*]] = icmp eq i8* [[PTR]], null
; CHECK-NEXT: br i1 [[ISNULL]], label [[RETURN:%.*]], label [[ELSE:%.*]]
; CHECK: else:
; CHECK-NEXT: [[LB:%.*]] = load i32, i32* [[B:%.*]], align 4
; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[LB]], 1
; CHECK-NEXT: store i32 [[ADD]], i32* [[B]]
; CHECK-NEXT: br label [[RETURN]]
; CHECK: return:
; CHECK-NEXT: ret i8* [[PTR]]
;
entry:
%ptr = getelementptr i8, i8* %ptr_op, i32 %i
%isnull = icmp eq i8* %ptr, null
br i1 %isnull, label %return, label %else
else:
%lb = load i32, i32* %b
%add = add nsw i32 %lb, 1
store i32 %add, i32* %b
br label %return
return:
%r = phi i8* [ %ptr, %else ], [ null, %entry ]
ret i8* %r
}
; The sub has 'nsw', so it is not safe to propagate that value along
; the bb2 edge because that would propagate poison to the return.
define i32 @PR43802(i32 %arg) {
; CHECK-LABEL: @PR43802(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[ARG:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[ARG]], -2147483648
; CHECK-NEXT: br i1 [[CMP]], label [[BB2:%.*]], label [[BB3:%.*]]
; CHECK: bb2:
; CHECK-NEXT: br label [[BB3]]
; CHECK: bb3:
; CHECK-NEXT: ret i32 [[SUB]]
;
entry:
%sub = sub nsw i32 0, %arg
%cmp = icmp eq i32 %arg, -2147483648
br i1 %cmp, label %bb2, label %bb3
bb2:
br label %bb3
bb3:
%r = phi i32 [ -2147483648, %bb2 ], [ %sub, %entry ]
ret i32 %r
}
|