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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -passes=instcombine < %s | FileCheck %s
;
; Tests to show cases where computeKnownBits should be able to determine
; the known bits of a phi edge based off a conditional branch feeding the phi.
;
; %x either eq 7 or is set to 7
define i64 @limit_i64_eq_7(i64 %x) {
; CHECK-LABEL: @limit_i64_eq_7(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[X:%.*]], 7
; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
; CHECK: body:
; CHECK-NEXT: br label [[END]]
; CHECK: end:
; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ 7, [[BODY]] ]
; CHECK-NEXT: ret i64 [[RES]]
;
entry:
%cmp = icmp eq i64 %x, 7
br i1 %cmp, label %end, label %body
body:
br label %end
end:
%res = phi i64 [ %x, %entry ], [ 7, %body ]
ret i64 %res
}
; %x either eq 255 or is set to 255
define i64 @limit_i64_ne_255(i64 %x) {
; CHECK-LABEL: @limit_i64_ne_255(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[X:%.*]], 255
; CHECK-NEXT: call void @use(i1 [[CMP]])
; CHECK-NEXT: br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]]
; CHECK: body:
; CHECK-NEXT: br label [[END]]
; CHECK: end:
; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ 255, [[BODY]] ]
; CHECK-NEXT: ret i64 [[RES]]
;
entry:
%cmp = icmp ne i64 %x, 255
call void @use(i1 %cmp)
br i1 %cmp, label %body, label %end
body:
br label %end
end:
%res = phi i64 [ %x, %entry ], [ 255, %body ]
ret i64 %res
}
declare void @use(i1)
; %x either ule 15 or is masked with 15
define i64 @limit_i64_ule_15(i64 %x) {
; CHECK-LABEL: @limit_i64_ule_15(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 16
; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
; CHECK: body:
; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 15
; CHECK-NEXT: br label [[END]]
; CHECK: end:
; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
; CHECK-NEXT: ret i64 [[X_MASK]]
;
entry:
%cmp = icmp ule i64 %x, 15
br i1 %cmp, label %end, label %body
body:
%mask = and i64 %x, 15
br label %end
end:
%x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
%res = and i64 %x.mask, 15
ret i64 %res
}
; %x either uge 8 or is masked with 7
define i64 @limit_i64_uge_8(i64 %x) {
; CHECK-LABEL: @limit_i64_uge_8(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[X:%.*]], 7
; CHECK-NEXT: br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]]
; CHECK: body:
; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 7
; CHECK-NEXT: br label [[END]]
; CHECK: end:
; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
; CHECK-NEXT: ret i64 [[X_MASK]]
;
entry:
%cmp = icmp uge i64 %x, 8
br i1 %cmp, label %body, label %end
body:
%mask = and i64 %x, 7
br label %end
end:
%x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
%res = and i64 %x.mask, 7
ret i64 %res
}
; %x either ult 8 or is masked with 7
define i64 @limit_i64_ult_8(i64 %x) {
; CHECK-LABEL: @limit_i64_ult_8(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 8
; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
; CHECK: body:
; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 7
; CHECK-NEXT: br label [[END]]
; CHECK: end:
; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
; CHECK-NEXT: ret i64 [[X_MASK]]
;
entry:
%cmp = icmp ult i64 %x, 8
br i1 %cmp, label %end, label %body
body:
%mask = and i64 %x, 7
br label %end
end:
%x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
%res = and i64 %x.mask, 7
ret i64 %res
}
; %x either ugt 7 or is masked with 7
define i64 @limit_i64_ugt_7(i64 %x) {
; CHECK-LABEL: @limit_i64_ugt_7(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[X:%.*]], 7
; CHECK-NEXT: br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]]
; CHECK: body:
; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 7
; CHECK-NEXT: br label [[END]]
; CHECK: end:
; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
; CHECK-NEXT: ret i64 [[X_MASK]]
;
entry:
%cmp = icmp ugt i64 %x, 7
br i1 %cmp, label %body, label %end
body:
%mask = and i64 %x, 7
br label %end
end:
%x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
%res = and i64 %x.mask, 7
ret i64 %res
}
;
; negative tests
;
; %x either ule 15 or is masked with 15
define i64 @limit_i64_ule_15_mask3(i64 %x) {
; CHECK-LABEL: @limit_i64_ule_15_mask3(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 16
; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
; CHECK: body:
; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 15
; CHECK-NEXT: br label [[END]]
; CHECK: end:
; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
; CHECK-NEXT: [[RES:%.*]] = and i64 [[X_MASK]], 3
; CHECK-NEXT: ret i64 [[RES]]
;
entry:
%cmp = icmp ule i64 %x, 15
br i1 %cmp, label %end, label %body
body:
%mask = and i64 %x, 15
br label %end
end:
%x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
%res = and i64 %x.mask, 3
ret i64 %res
}
; %x either ult 8 or is masked with 7
define i64 @limit_i64_ult_8_mask1(i64 %x) {
; CHECK-LABEL: @limit_i64_ult_8_mask1(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 8
; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
; CHECK: body:
; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 7
; CHECK-NEXT: br label [[END]]
; CHECK: end:
; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
; CHECK-NEXT: [[RES:%.*]] = and i64 [[X_MASK]], 1
; CHECK-NEXT: ret i64 [[RES]]
;
entry:
%cmp = icmp ult i64 %x, 8
br i1 %cmp, label %end, label %body
body:
%mask = and i64 %x, 7
br label %end
end:
%x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
%res = and i64 %x.mask, 1
ret i64 %res
}
|