303 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4declare i1 @barrier()5declare void @llvm.assume(i1)6declare void @use.i8(i8)7 8define i1 @icmp_ult_x_y(i8 %x, i8 %y) {9; CHECK-LABEL: @icmp_ult_x_y(10; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], [[Y:%.*]]11; CHECK-NEXT: [[Z:%.*]] = icmp ne i8 [[AND]], [[X]]12; CHECK-NEXT: ret i1 [[Z]]13;14 %and = and i8 %x, %y15 %z = icmp ult i8 %and, %x16 ret i1 %z17}18 19define i1 @icmp_ult_x_y_2(i8 %xx, i8 %y) {20; CHECK-LABEL: @icmp_ult_x_y_2(21; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], [[XX]]22; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], [[Y:%.*]]23; CHECK-NEXT: [[Z:%.*]] = icmp ne i8 [[AND]], [[X]]24; CHECK-NEXT: ret i1 [[Z]]25;26 %x = mul i8 %xx, %xx27 %and = and i8 %x, %y28 %z = icmp ugt i8 %x, %and29 ret i1 %z30}31 32define <2 x i1> @icmp_uge_x_y(<2 x i8> %x, <2 x i8> %y) {33; CHECK-LABEL: @icmp_uge_x_y(34; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[X:%.*]], [[Y:%.*]]35; CHECK-NEXT: [[Z:%.*]] = icmp eq <2 x i8> [[AND]], [[X]]36; CHECK-NEXT: ret <2 x i1> [[Z]]37;38 %and = and <2 x i8> %x, %y39 %z = icmp uge <2 x i8> %and, %x40 ret <2 x i1> %z41}42 43define i1 @icmp_uge_x_y_2(i8 %xx, i8 %y) {44; CHECK-LABEL: @icmp_uge_x_y_2(45; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], [[XX]]46; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], [[Y:%.*]]47; CHECK-NEXT: [[Z:%.*]] = icmp eq i8 [[AND]], [[X]]48; CHECK-NEXT: ret i1 [[Z]]49;50 %x = mul i8 %xx, %xx51 %and = and i8 %x, %y52 %z = icmp ule i8 %x, %and53 ret i1 %z54}55 56define i1 @icmp_sge_x_negy(i8 %x, i8 %y) {57; CHECK-LABEL: @icmp_sge_x_negy(58; CHECK-NEXT: [[CY:%.*]] = icmp slt i8 [[Y:%.*]], 059; CHECK-NEXT: call void @llvm.assume(i1 [[CY]])60; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], [[Y]]61; CHECK-NEXT: [[Z:%.*]] = icmp eq i8 [[AND]], [[X]]62; CHECK-NEXT: ret i1 [[Z]]63;64 %cy = icmp slt i8 %y, 065 call void @llvm.assume(i1 %cy)66 %and = and i8 %x, %y67 %z = icmp sge i8 %and, %x68 ret i1 %z69}70 71define i1 @icmp_slt_x_negy(i8 %x, i8 %y) {72; CHECK-LABEL: @icmp_slt_x_negy(73; CHECK-NEXT: [[CY:%.*]] = icmp slt i8 [[Y:%.*]], 074; CHECK-NEXT: br i1 [[CY]], label [[NEGY:%.*]], label [[POSY:%.*]]75; CHECK: negy:76; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], [[Y]]77; CHECK-NEXT: [[Z:%.*]] = icmp ne i8 [[AND]], [[X]]78; CHECK-NEXT: ret i1 [[Z]]79; CHECK: posy:80; CHECK-NEXT: [[R:%.*]] = call i1 @barrier()81; CHECK-NEXT: ret i1 [[R]]82;83 %cy = icmp slt i8 %y, 084 br i1 %cy, label %negy, label %posy85negy:86 %and = and i8 %x, %y87 %z = icmp slt i8 %and, %x88 ret i1 %z89posy:90 %r = call i1 @barrier()91 ret i1 %r92}93 94define i1 @icmp_slt_x_negy_fail_maybe_zero(i8 %x, i8 %y) {95; CHECK-LABEL: @icmp_slt_x_negy_fail_maybe_zero(96; CHECK-NEXT: [[CY:%.*]] = icmp slt i8 [[Y:%.*]], 197; CHECK-NEXT: br i1 [[CY]], label [[NEGY:%.*]], label [[POSY:%.*]]98; CHECK: negy:99; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], [[Y]]100; CHECK-NEXT: [[Z:%.*]] = icmp slt i8 [[AND]], [[X]]101; CHECK-NEXT: ret i1 [[Z]]102; CHECK: posy:103; CHECK-NEXT: [[R:%.*]] = call i1 @barrier()104; CHECK-NEXT: ret i1 [[R]]105;106 %cy = icmp sle i8 %y, 0107 br i1 %cy, label %negy, label %posy108negy:109 %and = and i8 %x, %y110 %z = icmp slt i8 %and, %x111 ret i1 %z112posy:113 %r = call i1 @barrier()114 ret i1 %r115}116 117define i1 @icmp_sle_x_negy(i8 %x, i8 %yy) {118; CHECK-LABEL: @icmp_sle_x_negy(119; CHECK-NEXT: ret i1 true120;121 %y = or i8 %yy, 128122 %and = and i8 %y, %x123 %z = icmp sle i8 %and, %x124 ret i1 %z125}126 127define <2 x i1> @icmp_sgt_x_negy(<2 x i8> %x, <2 x i8> %yy) {128; CHECK-LABEL: @icmp_sgt_x_negy(129; CHECK-NEXT: ret <2 x i1> zeroinitializer130;131 %y = or <2 x i8> %yy, <i8 128, i8 128>132 %and = and <2 x i8> %y, %x133 %z = icmp sgt <2 x i8> %and, %x134 ret <2 x i1> %z135}136 137define <2 x i1> @icmp_sgt_x_negy_fail_partial(<2 x i8> %x, <2 x i8> %yy) {138; CHECK-LABEL: @icmp_sgt_x_negy_fail_partial(139; CHECK-NEXT: [[Y:%.*]] = or <2 x i8> [[YY:%.*]], <i8 -128, i8 4>140; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[Y]], [[X:%.*]]141; CHECK-NEXT: [[Z:%.*]] = icmp sgt <2 x i8> [[AND]], [[X]]142; CHECK-NEXT: ret <2 x i1> [[Z]]143;144 %y = or <2 x i8> %yy, <i8 128, i8 4>145 %and = and <2 x i8> %y, %x146 %z = icmp sgt <2 x i8> %and, %x147 ret <2 x i1> %z148}149 150define <2 x i1> @icmp_sle_x_posy(<2 x i8> %x, <2 x i8> %yy) {151; CHECK-LABEL: @icmp_sle_x_posy(152; CHECK-NEXT: [[Z:%.*]] = icmp sgt <2 x i8> [[X:%.*]], splat (i8 -1)153; CHECK-NEXT: ret <2 x i1> [[Z]]154;155 %y = and <2 x i8> %yy, <i8 127, i8 127>156 %and = and <2 x i8> %y, %x157 %z = icmp sle <2 x i8> %and, %x158 ret <2 x i1> %z159}160 161define <2 x i1> @icmp_sle_x_posy_fail_partial(<2 x i8> %x, <2 x i8> %yy) {162; CHECK-LABEL: @icmp_sle_x_posy_fail_partial(163; CHECK-NEXT: [[Y:%.*]] = and <2 x i8> [[YY:%.*]], <i8 127, i8 -65>164; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[Y]], [[X:%.*]]165; CHECK-NEXT: [[Z:%.*]] = icmp sle <2 x i8> [[AND]], [[X]]166; CHECK-NEXT: ret <2 x i1> [[Z]]167;168 %y = and <2 x i8> %yy, <i8 127, i8 191>169 %and = and <2 x i8> %y, %x170 %z = icmp sle <2 x i8> %and, %x171 ret <2 x i1> %z172}173 174define i1 @icmp_sgt_x_posy(i8 %x, i8 %y) {175; CHECK-LABEL: @icmp_sgt_x_posy(176; CHECK-NEXT: [[CY:%.*]] = icmp sgt i8 [[Y:%.*]], -1177; CHECK-NEXT: call void @llvm.assume(i1 [[CY]])178; CHECK-NEXT: [[Z:%.*]] = icmp slt i8 [[X:%.*]], 0179; CHECK-NEXT: ret i1 [[Z]]180;181 %cy = icmp sge i8 %y, 0182 call void @llvm.assume(i1 %cy)183 %and = and i8 %x, %y184 %z = icmp sgt i8 %and, %x185 ret i1 %z186}187 188define <2 x i1> @icmp_sgt_negx_y(<2 x i8> %xx, <2 x i8> %y) {189; CHECK-LABEL: @icmp_sgt_negx_y(190; CHECK-NEXT: [[Z:%.*]] = icmp sgt <2 x i8> [[Y:%.*]], splat (i8 -1)191; CHECK-NEXT: ret <2 x i1> [[Z]]192;193 %x = or <2 x i8> %xx, <i8 128, i8 128>194 %and = and <2 x i8> %x, %y195 %z = icmp sgt <2 x i8> %and, %x196 ret <2 x i1> %z197}198 199define i1 @icmp_sle_negx_y(i8 %x, i8 %y) {200; CHECK-LABEL: @icmp_sle_negx_y(201; CHECK-NEXT: [[CX:%.*]] = icmp slt i8 [[X:%.*]], 0202; CHECK-NEXT: call void @llvm.assume(i1 [[CX]])203; CHECK-NEXT: [[Z:%.*]] = icmp slt i8 [[Y:%.*]], 0204; CHECK-NEXT: ret i1 [[Z]]205;206 %cx = icmp slt i8 %x, 0207 call void @llvm.assume(i1 %cx)208 %and = and i8 %x, %y209 %z = icmp sle i8 %and, %x210 ret i1 %z211}212 213define i1 @icmp_sle_negx_y_fail_maybe_zero(i8 %x, i8 %y) {214; CHECK-LABEL: @icmp_sle_negx_y_fail_maybe_zero(215; CHECK-NEXT: [[CX:%.*]] = icmp slt i8 [[X:%.*]], 1216; CHECK-NEXT: call void @llvm.assume(i1 [[CX]])217; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], [[Y:%.*]]218; CHECK-NEXT: [[Z:%.*]] = icmp sle i8 [[AND]], [[X]]219; CHECK-NEXT: ret i1 [[Z]]220;221 %cx = icmp sle i8 %x, 0222 call void @llvm.assume(i1 %cx)223 %and = and i8 %x, %y224 %z = icmp sle i8 %and, %x225 ret i1 %z226}227 228define i1 @icmp_eq_x_invertable_y_todo(i8 %x, i1 %y) {229; CHECK-LABEL: @icmp_eq_x_invertable_y_todo(230; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[Y:%.*]], i8 -8, i8 -25231; CHECK-NEXT: [[TMP2:%.*]] = and i8 [[X:%.*]], [[TMP1]]232; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[TMP2]], 0233; CHECK-NEXT: ret i1 [[R]]234;235 %yy = select i1 %y, i8 7, i8 24236 %and = and i8 %x, %yy237 %r = icmp eq i8 %x, %and238 ret i1 %r239}240 241define i1 @icmp_eq_x_invertable_y(i8 %x, i8 %y) {242; CHECK-LABEL: @icmp_eq_x_invertable_y(243; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], [[Y:%.*]]244; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[TMP1]], 0245; CHECK-NEXT: ret i1 [[R]]246;247 %yy = xor i8 %y, -1248 %and = and i8 %x, %yy249 %r = icmp eq i8 %x, %and250 ret i1 %r251}252 253define i1 @icmp_eq_x_invertable_y_fail_multiuse(i8 %x, i8 %y) {254; CHECK-LABEL: @icmp_eq_x_invertable_y_fail_multiuse(255; CHECK-NEXT: [[YY:%.*]] = xor i8 [[Y:%.*]], -1256; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], [[YY]]257; CHECK-NEXT: call void @use.i8(i8 [[AND]])258; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[X]], [[AND]]259; CHECK-NEXT: ret i1 [[R]]260;261 %yy = xor i8 %y, -1262 %and = and i8 %x, %yy263 call void @use.i8(i8 %and)264 %r = icmp eq i8 %x, %and265 ret i1 %r266}267 268define i1 @icmp_eq_x_invertable_y2_todo(i8 %x, i1 %y) {269; CHECK-LABEL: @icmp_eq_x_invertable_y2_todo(270; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[Y:%.*]], i8 -8, i8 -25271; CHECK-NEXT: [[TMP2:%.*]] = or i8 [[X:%.*]], [[TMP1]]272; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[TMP2]], -1273; CHECK-NEXT: ret i1 [[R]]274;275 %yy = select i1 %y, i8 7, i8 24276 %and = and i8 %x, %yy277 %r = icmp eq i8 %yy, %and278 ret i1 %r279}280 281define i1 @icmp_eq_x_invertable_y2(i8 %x, i8 %y) {282; CHECK-LABEL: @icmp_eq_x_invertable_y2(283; CHECK-NEXT: [[TMP1:%.*]] = or i8 [[X:%.*]], [[Y:%.*]]284; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[TMP1]], -1285; CHECK-NEXT: ret i1 [[R]]286;287 %yy = xor i8 %y, -1288 %and = and i8 %x, %yy289 %r = icmp eq i8 %yy, %and290 ret i1 %r291}292 293define i1 @icmp_eq_x_invertable_y_fail_immconstant(i8 %x, i8 %y) {294; CHECK-LABEL: @icmp_eq_x_invertable_y_fail_immconstant(295; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 7296; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 7297; CHECK-NEXT: ret i1 [[R]]298;299 %and = and i8 %x, 7300 %r = icmp eq i8 %and, 7301 ret i1 %r302}303