510 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4declare void @use.i8(i8)5declare void @use.v2i4(<2 x i4>)6declare void @use.i1(i1)7 8declare void @llvm.assume(i1)9 10; Basic pattern11define i8 @t0(i8 %x) {12; CHECK-LABEL: @t0(13; CHECK-NEXT: [[X_BIASED:%.*]] = add i8 [[X:%.*]], 1514; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = and i8 [[X_BIASED]], -1615; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]16;17 %x.lowbits = and i8 %x, 1518 %x.lowbits.are.zero = icmp eq i8 %x.lowbits, 019 %x.biased = add i8 %x, 1620 %x.biased.highbits = and i8 %x.biased, -1621 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x, i8 %x.biased.highbits22 ret i8 %x.roundedup23}24 25; Another alignment is fine26define i8 @t1(i8 %x) {27; CHECK-LABEL: @t1(28; CHECK-NEXT: [[X_BIASED:%.*]] = add i8 [[X:%.*]], 3129; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = and i8 [[X_BIASED]], -3230; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]31;32 %x.lowbits = and i8 %x, 3133 %x.lowbits.are.zero = icmp eq i8 %x.lowbits, 034 %x.biased = add i8 %x, 3235 %x.biased.highbits = and i8 %x.biased, -3236 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x, i8 %x.biased.highbits37 ret i8 %x.roundedup38}39 40; Bias can be either the alignment or alignment-141define i8 @t2(i8 %x) {42; CHECK-LABEL: @t2(43; CHECK-NEXT: [[X_BIASED1:%.*]] = add i8 [[X:%.*]], 1544; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = and i8 [[X_BIASED1]], -1645; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]46;47 %x.lowbits = and i8 %x, 1548 %x.lowbits.are.zero = icmp eq i8 %x.lowbits, 049 %x.biased = add i8 %x, 1550 %x.biased.highbits = and i8 %x.biased, -1651 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x, i8 %x.biased.highbits52 ret i8 %x.roundedup53}54 55; select is commutative56define i8 @t3_commutative(i8 %x) {57; CHECK-LABEL: @t3_commutative(58; CHECK-NEXT: [[X_LOWBITS:%.*]] = and i8 [[X:%.*]], 1559; CHECK-NEXT: [[X_LOWBITS_ARE_NOT_ZERO:%.*]] = icmp ne i8 [[X_LOWBITS]], 060; CHECK-NEXT: call void @use.i1(i1 [[X_LOWBITS_ARE_NOT_ZERO]])61; CHECK-NEXT: [[X_BIASED:%.*]] = add i8 [[X]], 1562; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = and i8 [[X_BIASED]], -1663; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]64;65 %x.lowbits = and i8 %x, 1566 %x.lowbits.are.not.zero = icmp ne i8 %x.lowbits, 067 call void @use.i1(i1 %x.lowbits.are.not.zero)68 %x.biased = add i8 %x, 1669 %x.biased.highbits = and i8 %x.biased, -1670 %x.roundedup = select i1 %x.lowbits.are.not.zero, i8 %x.biased.highbits, i8 %x71 ret i8 %x.roundedup72}73 74; Basic splat vector test75define <2 x i8> @t4_splat(<2 x i8> %x) {76; CHECK-LABEL: @t4_splat(77; CHECK-NEXT: [[X_BIASED:%.*]] = add <2 x i8> [[X:%.*]], splat (i8 15)78; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = and <2 x i8> [[X_BIASED]], splat (i8 -16)79; CHECK-NEXT: ret <2 x i8> [[X_ROUNDEDUP]]80;81 %x.lowbits = and <2 x i8> %x, <i8 15, i8 15>82 %x.lowbits.are.zero = icmp eq <2 x i8> %x.lowbits, <i8 0, i8 0>83 %x.biased = add <2 x i8> %x, <i8 16, i8 16>84 %x.biased.highbits = and <2 x i8> %x.biased, <i8 -16, i8 -16>85 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i8> %x, <2 x i8> %x.biased.highbits86 ret <2 x i8> %x.roundedup87}88 89; Splat-with-poison90define <2 x i8> @t5_splat_poison_0b0001(<2 x i8> %x) {91; CHECK-LABEL: @t5_splat_poison_0b0001(92; CHECK-NEXT: [[X_BIASED1:%.*]] = add <2 x i8> [[X:%.*]], splat (i8 15)93; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = and <2 x i8> [[X_BIASED1]], splat (i8 -16)94; CHECK-NEXT: ret <2 x i8> [[X_ROUNDEDUP]]95;96 %x.lowbits = and <2 x i8> %x, <i8 15, i8 15>97 %x.lowbits.are.zero = icmp eq <2 x i8> %x.lowbits, <i8 0, i8 0>98 %x.biased = add <2 x i8> %x, <i8 16, i8 16>99 %x.biased.highbits = and <2 x i8> %x.biased, <i8 -16, i8 poison>100 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i8> %x, <2 x i8> %x.biased.highbits101 ret <2 x i8> %x.roundedup102}103define <2 x i8> @t5_splat_poison_0b0010(<2 x i8> %x) {104; CHECK-LABEL: @t5_splat_poison_0b0010(105; CHECK-NEXT: [[X_BIASED1:%.*]] = add <2 x i8> [[X:%.*]], splat (i8 15)106; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = and <2 x i8> [[X_BIASED1]], splat (i8 -16)107; CHECK-NEXT: ret <2 x i8> [[X_ROUNDEDUP]]108;109 %x.lowbits = and <2 x i8> %x, <i8 15, i8 15>110 %x.lowbits.are.zero = icmp eq <2 x i8> %x.lowbits, <i8 0, i8 0>111 %x.biased = add <2 x i8> %x, <i8 16, i8 poison>112 %x.biased.highbits = and <2 x i8> %x.biased, <i8 -16, i8 -16>113 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i8> %x, <2 x i8> %x.biased.highbits114 ret <2 x i8> %x.roundedup115}116define <2 x i8> @t5_splat_poison_0b0100(<2 x i8> %x) {117; CHECK-LABEL: @t5_splat_poison_0b0100(118; CHECK-NEXT: [[X_BIASED:%.*]] = add <2 x i8> [[X:%.*]], splat (i8 15)119; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = and <2 x i8> [[X_BIASED]], splat (i8 -16)120; CHECK-NEXT: ret <2 x i8> [[X_ROUNDEDUP]]121;122 %x.lowbits = and <2 x i8> %x, <i8 15, i8 15>123 %x.lowbits.are.zero = icmp eq <2 x i8> %x.lowbits, <i8 0, i8 poison>124 %x.biased = add <2 x i8> %x, <i8 16, i8 16>125 %x.biased.highbits = and <2 x i8> %x.biased, <i8 -16, i8 -16>126 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i8> %x, <2 x i8> %x.biased.highbits127 ret <2 x i8> %x.roundedup128}129define <2 x i8> @t5_splat_poison_0b1000(<2 x i8> %x) {130; CHECK-LABEL: @t5_splat_poison_0b1000(131; CHECK-NEXT: [[X_BIASED:%.*]] = add <2 x i8> [[X:%.*]], splat (i8 15)132; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = and <2 x i8> [[X_BIASED]], splat (i8 -16)133; CHECK-NEXT: ret <2 x i8> [[X_ROUNDEDUP]]134;135 %x.lowbits = and <2 x i8> %x, <i8 15, i8 poison>136 %x.lowbits.are.zero = icmp eq <2 x i8> %x.lowbits, <i8 0, i8 0>137 %x.biased = add <2 x i8> %x, <i8 16, i8 16>138 %x.biased.highbits = and <2 x i8> %x.biased, <i8 -16, i8 -16>139 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i8> %x, <2 x i8> %x.biased.highbits140 ret <2 x i8> %x.roundedup141}142 143; Basic non-splat vector test144define <2 x i8> @t6_nonsplat(<2 x i8> %x) {145; CHECK-LABEL: @t6_nonsplat(146; CHECK-NEXT: [[X_LOWBITS:%.*]] = and <2 x i8> [[X:%.*]], <i8 15, i8 31>147; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq <2 x i8> [[X_LOWBITS]], zeroinitializer148; CHECK-NEXT: [[X_BIASED:%.*]] = add <2 x i8> [[X]], <i8 16, i8 32>149; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = and <2 x i8> [[X_BIASED]], <i8 -16, i8 -32>150; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select <2 x i1> [[X_LOWBITS_ARE_ZERO]], <2 x i8> [[X]], <2 x i8> [[X_BIASED_HIGHBITS]]151; CHECK-NEXT: ret <2 x i8> [[X_ROUNDEDUP]]152;153 %x.lowbits = and <2 x i8> %x, <i8 15, i8 31>154 %x.lowbits.are.zero = icmp eq <2 x i8> %x.lowbits, <i8 0, i8 0>155 %x.biased = add <2 x i8> %x, <i8 16, i8 32>156 %x.biased.highbits = and <2 x i8> %x.biased, <i8 -16, i8 -32>157 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i8> %x, <2 x i8> %x.biased.highbits158 ret <2 x i8> %x.roundedup159}160 161; Even if the alignment (and masks) are splat, the bias could be non-splat162define <2 x i8> @t7_nonsplat_bias(<2 x i8> %x) {163; CHECK-LABEL: @t7_nonsplat_bias(164; CHECK-NEXT: [[X_LOWBITS:%.*]] = and <2 x i8> [[X:%.*]], splat (i8 15)165; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq <2 x i8> [[X_LOWBITS]], zeroinitializer166; CHECK-NEXT: [[X_BIASED:%.*]] = add <2 x i8> [[X]], <i8 15, i8 16>167; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = and <2 x i8> [[X_BIASED]], splat (i8 -16)168; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select <2 x i1> [[X_LOWBITS_ARE_ZERO]], <2 x i8> [[X]], <2 x i8> [[X_BIASED_HIGHBITS]]169; CHECK-NEXT: ret <2 x i8> [[X_ROUNDEDUP]]170;171 %x.lowbits = and <2 x i8> %x, <i8 15, i8 15>172 %x.lowbits.are.zero = icmp eq <2 x i8> %x.lowbits, <i8 0, i8 0>173 %x.biased = add <2 x i8> %x, <i8 15, i8 16>174 %x.biased.highbits = and <2 x i8> %x.biased, <i8 -16, i8 -16>175 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i8> %x, <2 x i8> %x.biased.highbits176 ret <2 x i8> %x.roundedup177}178 179; Splat-in-disguise vector tests180define <2 x i8> @t8_nonsplat_masked_by_poison_0b0001(<2 x i8> %x) {181; CHECK-LABEL: @t8_nonsplat_masked_by_poison_0b0001(182; CHECK-NEXT: [[X_LOWBITS:%.*]] = and <2 x i8> [[X:%.*]], <i8 15, i8 31>183; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq <2 x i8> [[X_LOWBITS]], zeroinitializer184; CHECK-NEXT: [[X_BIASED:%.*]] = add <2 x i8> [[X]], <i8 16, i8 32>185; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = and <2 x i8> [[X_BIASED]], <i8 -16, i8 poison>186; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select <2 x i1> [[X_LOWBITS_ARE_ZERO]], <2 x i8> [[X]], <2 x i8> [[X_BIASED_HIGHBITS]]187; CHECK-NEXT: ret <2 x i8> [[X_ROUNDEDUP]]188;189 %x.lowbits = and <2 x i8> %x, <i8 15, i8 31>190 %x.lowbits.are.zero = icmp eq <2 x i8> %x.lowbits, <i8 0, i8 0>191 %x.biased = add <2 x i8> %x, <i8 16, i8 32>192 %x.biased.highbits = and <2 x i8> %x.biased, <i8 -16, i8 poison>193 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i8> %x, <2 x i8> %x.biased.highbits194 ret <2 x i8> %x.roundedup195}196define <2 x i8> @t8_nonsplat_masked_by_poison_0b0010(<2 x i8> %x) {197; CHECK-LABEL: @t8_nonsplat_masked_by_poison_0b0010(198; CHECK-NEXT: [[X_LOWBITS:%.*]] = and <2 x i8> [[X:%.*]], <i8 15, i8 31>199; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq <2 x i8> [[X_LOWBITS]], zeroinitializer200; CHECK-NEXT: [[X_BIASED:%.*]] = add <2 x i8> [[X]], <i8 16, i8 poison>201; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = and <2 x i8> [[X_BIASED]], <i8 -16, i8 -32>202; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select <2 x i1> [[X_LOWBITS_ARE_ZERO]], <2 x i8> [[X]], <2 x i8> [[X_BIASED_HIGHBITS]]203; CHECK-NEXT: ret <2 x i8> [[X_ROUNDEDUP]]204;205 %x.lowbits = and <2 x i8> %x, <i8 15, i8 31>206 %x.lowbits.are.zero = icmp eq <2 x i8> %x.lowbits, <i8 0, i8 0>207 %x.biased = add <2 x i8> %x, <i8 16, i8 poison>208 %x.biased.highbits = and <2 x i8> %x.biased, <i8 -16, i8 -32>209 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i8> %x, <2 x i8> %x.biased.highbits210 ret <2 x i8> %x.roundedup211}212define <2 x i8> @t8_nonsplat_masked_by_poison_0b0100(<2 x i8> %x) {213; CHECK-LABEL: @t8_nonsplat_masked_by_poison_0b0100(214; CHECK-NEXT: [[X_LOWBITS:%.*]] = and <2 x i8> [[X:%.*]], <i8 15, i8 31>215; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq <2 x i8> [[X_LOWBITS]], <i8 0, i8 poison>216; CHECK-NEXT: [[X_BIASED:%.*]] = add <2 x i8> [[X]], <i8 16, i8 32>217; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = and <2 x i8> [[X_BIASED]], <i8 -16, i8 -32>218; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select <2 x i1> [[X_LOWBITS_ARE_ZERO]], <2 x i8> [[X]], <2 x i8> [[X_BIASED_HIGHBITS]]219; CHECK-NEXT: ret <2 x i8> [[X_ROUNDEDUP]]220;221 %x.lowbits = and <2 x i8> %x, <i8 15, i8 31>222 %x.lowbits.are.zero = icmp eq <2 x i8> %x.lowbits, <i8 0, i8 poison>223 %x.biased = add <2 x i8> %x, <i8 16, i8 32>224 %x.biased.highbits = and <2 x i8> %x.biased, <i8 -16, i8 -32>225 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i8> %x, <2 x i8> %x.biased.highbits226 ret <2 x i8> %x.roundedup227}228define <2 x i8> @t8_nonsplat_masked_by_poison_0b1000(<2 x i8> %x) {229; CHECK-LABEL: @t8_nonsplat_masked_by_poison_0b1000(230; CHECK-NEXT: [[X_LOWBITS:%.*]] = and <2 x i8> [[X:%.*]], <i8 15, i8 poison>231; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq <2 x i8> [[X_LOWBITS]], zeroinitializer232; CHECK-NEXT: [[X_BIASED:%.*]] = add <2 x i8> [[X]], <i8 16, i8 32>233; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = and <2 x i8> [[X_BIASED]], <i8 -16, i8 -32>234; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select <2 x i1> [[X_LOWBITS_ARE_ZERO]], <2 x i8> [[X]], <2 x i8> [[X_BIASED_HIGHBITS]]235; CHECK-NEXT: ret <2 x i8> [[X_ROUNDEDUP]]236;237 %x.lowbits = and <2 x i8> %x, <i8 15, i8 poison>238 %x.lowbits.are.zero = icmp eq <2 x i8> %x.lowbits, <i8 0, i8 0>239 %x.biased = add <2 x i8> %x, <i8 16, i8 32>240 %x.biased.highbits = and <2 x i8> %x.biased, <i8 -16, i8 -32>241 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i8> %x, <2 x i8> %x.biased.highbits242 ret <2 x i8> %x.roundedup243}244 245; The X are different246define i8 @n9_wrong_x0(i8 %x.0, i8 %x.1) {247; CHECK-LABEL: @n9_wrong_x0(248; CHECK-NEXT: [[X_LOWBITS:%.*]] = and i8 [[X_0:%.*]], 15249; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq i8 [[X_LOWBITS]], 0250; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X_0]], -16251; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = add i8 [[TMP1]], 16252; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select i1 [[X_LOWBITS_ARE_ZERO]], i8 [[X_1:%.*]], i8 [[X_BIASED_HIGHBITS]]253; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]254;255 %x.lowbits = and i8 %x.0, 15256 %x.lowbits.are.zero = icmp eq i8 %x.lowbits, 0257 %x.biased = add i8 %x.0, 16258 %x.biased.highbits = and i8 %x.biased, -16259 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x.1, i8 %x.biased.highbits260 ret i8 %x.roundedup261}262define i8 @n9_wrong_x1(i8 %x.0, i8 %x.1) {263; CHECK-LABEL: @n9_wrong_x1(264; CHECK-NEXT: [[X_LOWBITS:%.*]] = and i8 [[X_0:%.*]], 15265; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq i8 [[X_LOWBITS]], 0266; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X_1:%.*]], -16267; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = add i8 [[TMP1]], 16268; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select i1 [[X_LOWBITS_ARE_ZERO]], i8 [[X_0]], i8 [[X_BIASED_HIGHBITS]]269; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]270;271 %x.lowbits = and i8 %x.0, 15272 %x.lowbits.are.zero = icmp eq i8 %x.lowbits, 0273 %x.biased = add i8 %x.1, 16274 %x.biased.highbits = and i8 %x.biased, -16275 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x.0, i8 %x.biased.highbits276 ret i8 %x.roundedup277}278define i8 @n9_wrong_x2(i8 %x.0, i8 %x.1) {279; CHECK-LABEL: @n9_wrong_x2(280; CHECK-NEXT: [[X_LOWBITS:%.*]] = and i8 [[X_1:%.*]], 15281; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq i8 [[X_LOWBITS]], 0282; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X_0:%.*]], -16283; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = add i8 [[TMP1]], 16284; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select i1 [[X_LOWBITS_ARE_ZERO]], i8 [[X_0]], i8 [[X_BIASED_HIGHBITS]]285; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]286;287 %x.lowbits = and i8 %x.1, 15288 %x.lowbits.are.zero = icmp eq i8 %x.lowbits, 0289 %x.biased = add i8 %x.0, 16290 %x.biased.highbits = and i8 %x.biased, -16291 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x.0, i8 %x.biased.highbits292 ret i8 %x.roundedup293}294 295; Wrong low-bit mask296define i8 @n10_wrong_low_bit_mask(i8 %x) {297; CHECK-LABEL: @n10_wrong_low_bit_mask(298; CHECK-NEXT: [[X_LOWBITS:%.*]] = and i8 [[X:%.*]], 31299; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq i8 [[X_LOWBITS]], 0300; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], -16301; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = add i8 [[TMP1]], 16302; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select i1 [[X_LOWBITS_ARE_ZERO]], i8 [[X]], i8 [[X_BIASED_HIGHBITS]]303; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]304;305 %x.lowbits = and i8 %x, 31306 %x.lowbits.are.zero = icmp eq i8 %x.lowbits, 0307 %x.biased = add i8 %x, 16308 %x.biased.highbits = and i8 %x.biased, -16309 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x, i8 %x.biased.highbits310 ret i8 %x.roundedup311}312 313; Wrong high-bit mask314define i8 @n11_wrong_high_bit_mask(i8 %x) {315; CHECK-LABEL: @n11_wrong_high_bit_mask(316; CHECK-NEXT: [[X_LOWBITS:%.*]] = and i8 [[X:%.*]], 15317; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq i8 [[X_LOWBITS]], 0318; CHECK-NEXT: [[X_BIASED:%.*]] = add i8 [[X]], 16319; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = and i8 [[X_BIASED]], -32320; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select i1 [[X_LOWBITS_ARE_ZERO]], i8 [[X]], i8 [[X_BIASED_HIGHBITS]]321; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]322;323 %x.lowbits = and i8 %x, 15324 %x.lowbits.are.zero = icmp eq i8 %x.lowbits, 0325 %x.biased = add i8 %x, 16326 %x.biased.highbits = and i8 %x.biased, -32327 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x, i8 %x.biased.highbits328 ret i8 %x.roundedup329}330 331; Wrong bias332define i8 @n12_wrong_bias(i8 %x) {333; CHECK-LABEL: @n12_wrong_bias(334; CHECK-NEXT: [[X_LOWBITS:%.*]] = and i8 [[X:%.*]], 15335; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq i8 [[X_LOWBITS]], 0336; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], -16337; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = add i8 [[TMP1]], 32338; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select i1 [[X_LOWBITS_ARE_ZERO]], i8 [[X]], i8 [[X_BIASED_HIGHBITS]]339; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]340;341 %x.lowbits = and i8 %x, 15342 %x.lowbits.are.zero = icmp eq i8 %x.lowbits, 0343 %x.biased = add i8 %x, 32344 %x.biased.highbits = and i8 %x.biased, -16345 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x, i8 %x.biased.highbits346 ret i8 %x.roundedup347}348 349; Wrong constants350define i8 @n13_wrong_constants_alignment_is_not_power_of_two(i8 %x) {351; CHECK-LABEL: @n13_wrong_constants_alignment_is_not_power_of_two(352; CHECK-NEXT: [[X_LOWBITS:%.*]] = and i8 [[X:%.*]], 2353; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq i8 [[X_LOWBITS]], 0354; CHECK-NEXT: [[X_BIASED:%.*]] = add i8 [[X]], 3355; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = and i8 [[X_BIASED]], -3356; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select i1 [[X_LOWBITS_ARE_ZERO]], i8 [[X]], i8 [[X_BIASED_HIGHBITS]]357; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]358;359 %x.lowbits = and i8 %x, 2360 %x.lowbits.are.zero = icmp eq i8 %x.lowbits, 0361 %x.biased = add i8 %x, 3362 %x.biased.highbits = and i8 %x.biased, -3363 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x, i8 %x.biased.highbits364 ret i8 %x.roundedup365}366 367; Comparison is not with zero368define i8 @n14_wrong_comparison_constant(i8 %x) {369; CHECK-LABEL: @n14_wrong_comparison_constant(370; CHECK-NEXT: [[X_LOWBITS:%.*]] = and i8 [[X:%.*]], 15371; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq i8 [[X_LOWBITS]], 1372; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], -16373; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = add i8 [[TMP1]], 16374; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select i1 [[X_LOWBITS_ARE_ZERO]], i8 [[X]], i8 [[X_BIASED_HIGHBITS]]375; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]376;377 %x.lowbits = and i8 %x, 15378 %x.lowbits.are.zero = icmp eq i8 %x.lowbits, 1379 %x.biased = add i8 %x, 16380 %x.biased.highbits = and i8 %x.biased, -16381 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x, i8 %x.biased.highbits382 ret i8 %x.roundedup383}384 385; Wrong comparison386define i8 @n15_wrong_comparison_predicate_and_constant(i8 %x) {387; CHECK-LABEL: @n15_wrong_comparison_predicate_and_constant(388; CHECK-NEXT: [[X_LOWBITS:%.*]] = and i8 [[X:%.*]], 14389; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq i8 [[X_LOWBITS]], 0390; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], -16391; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = add i8 [[TMP1]], 16392; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select i1 [[X_LOWBITS_ARE_ZERO]], i8 [[X]], i8 [[X_BIASED_HIGHBITS]]393; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]394;395 %x.lowbits = and i8 %x, 15396 %x.lowbits.are.zero = icmp ult i8 %x.lowbits, 2397 %x.biased = add i8 %x, 16398 %x.biased.highbits = and i8 %x.biased, -16399 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x, i8 %x.biased.highbits400 ret i8 %x.roundedup401}402 403; %x.biased.highbits must not have other uses404define i8 @n16_oneuse(i8 %x) {405; CHECK-LABEL: @n16_oneuse(406; CHECK-NEXT: [[X_LOWBITS:%.*]] = and i8 [[X:%.*]], 15407; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq i8 [[X_LOWBITS]], 0408; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], -16409; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = add i8 [[TMP1]], 16410; CHECK-NEXT: call void @use.i8(i8 [[X_BIASED_HIGHBITS]])411; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select i1 [[X_LOWBITS_ARE_ZERO]], i8 [[X]], i8 [[X_BIASED_HIGHBITS]]412; CHECK-NEXT: ret i8 [[X_ROUNDEDUP]]413;414 %x.lowbits = and i8 %x, 15415 %x.lowbits.are.zero = icmp eq i8 %x.lowbits, 0416 %x.biased = add i8 %x, 16417 %x.biased.highbits = and i8 %x.biased, -16418 call void @use.i8(i8 %x.biased.highbits)419 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x, i8 %x.biased.highbits420 ret i8 %x.roundedup421}422 423; But if bias is equal to low-bit mask, then we *could* just replace %x.roundedup with %x.biased.highbits424define i8 @t17_oneuse(i8 %x) {425; CHECK-LABEL: @t17_oneuse(426; CHECK-NEXT: [[X_BIASED:%.*]] = add i8 [[X:%.*]], 15427; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = and i8 [[X_BIASED]], -16428; CHECK-NEXT: call void @use.i8(i8 [[X_BIASED_HIGHBITS]])429; CHECK-NEXT: ret i8 [[X_BIASED_HIGHBITS]]430;431 %x.lowbits = and i8 %x, 15432 %x.lowbits.are.zero = icmp eq i8 %x.lowbits, 0433 %x.biased = add i8 %x, 15434 %x.biased.highbits = and i8 %x.biased, -16435 call void @use.i8(i8 %x.biased.highbits)436 %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x, i8 %x.biased.highbits437 ret i8 %x.roundedup438}439 440; Negative test: We can't replace with %x.biased.highbits because it is441; more poisonous.442define <2 x i4> @t18_replacement_0b0001(<2 x i4> %x) {443; CHECK-LABEL: @t18_replacement_0b0001(444; CHECK-NEXT: [[X_LOWBITS:%.*]] = and <2 x i4> [[X:%.*]], splat (i4 3)445; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq <2 x i4> [[X_LOWBITS]], zeroinitializer446; CHECK-NEXT: [[X_BIASED:%.*]] = add <2 x i4> [[X]], splat (i4 3)447; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = and <2 x i4> [[X_BIASED]], <i4 -4, i4 poison>448; CHECK-NEXT: call void @use.v2i4(<2 x i4> [[X_BIASED_HIGHBITS]])449; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select <2 x i1> [[X_LOWBITS_ARE_ZERO]], <2 x i4> [[X]], <2 x i4> [[X_BIASED_HIGHBITS]]450; CHECK-NEXT: ret <2 x i4> [[X_ROUNDEDUP]]451;452 %x.lowbits = and <2 x i4> %x, <i4 3, i4 3>453 %x.lowbits.are.zero = icmp eq <2 x i4> %x.lowbits, <i4 0, i4 0>454 %x.biased = add <2 x i4> %x, <i4 3, i4 3>455 %x.biased.highbits = and <2 x i4> %x.biased, <i4 -4, i4 poison>456 call void @use.v2i4(<2 x i4> %x.biased.highbits)457 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i4> %x, <2 x i4> %x.biased.highbits458 ret <2 x i4> %x.roundedup459}460; Negative test: We can't replace with %x.biased.highbits because it is461; more poisonous.462define <2 x i4> @t18_replacement_0b0010(<2 x i4> %x) {463; CHECK-LABEL: @t18_replacement_0b0010(464; CHECK-NEXT: [[X_LOWBITS:%.*]] = and <2 x i4> [[X:%.*]], splat (i4 3)465; CHECK-NEXT: [[X_LOWBITS_ARE_ZERO:%.*]] = icmp eq <2 x i4> [[X_LOWBITS]], zeroinitializer466; CHECK-NEXT: [[X_BIASED:%.*]] = add <2 x i4> [[X]], <i4 3, i4 poison>467; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = and <2 x i4> [[X_BIASED]], splat (i4 -4)468; CHECK-NEXT: call void @use.v2i4(<2 x i4> [[X_BIASED_HIGHBITS]])469; CHECK-NEXT: [[X_ROUNDEDUP:%.*]] = select <2 x i1> [[X_LOWBITS_ARE_ZERO]], <2 x i4> [[X]], <2 x i4> [[X_BIASED_HIGHBITS]]470; CHECK-NEXT: ret <2 x i4> [[X_ROUNDEDUP]]471;472 %x.lowbits = and <2 x i4> %x, <i4 3, i4 3>473 %x.lowbits.are.zero = icmp eq <2 x i4> %x.lowbits, <i4 0, i4 0>474 %x.biased = add <2 x i4> %x, <i4 3, i4 poison>475 %x.biased.highbits = and <2 x i4> %x.biased, <i4 -4, i4 -4>476 call void @use.v2i4(<2 x i4> %x.biased.highbits)477 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i4> %x, <2 x i4> %x.biased.highbits478 ret <2 x i4> %x.roundedup479}480define <2 x i4> @t18_replacement_0b0100(<2 x i4> %x) {481; CHECK-LABEL: @t18_replacement_0b0100(482; CHECK-NEXT: [[X_BIASED:%.*]] = add <2 x i4> [[X:%.*]], splat (i4 3)483; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = and <2 x i4> [[X_BIASED]], splat (i4 -4)484; CHECK-NEXT: call void @use.v2i4(<2 x i4> [[X_BIASED_HIGHBITS]])485; CHECK-NEXT: ret <2 x i4> [[X_BIASED_HIGHBITS]]486;487 %x.lowbits = and <2 x i4> %x, <i4 3, i4 3>488 %x.lowbits.are.zero = icmp eq <2 x i4> %x.lowbits, <i4 0, i4 poison>489 %x.biased = add <2 x i4> %x, <i4 3, i4 3>490 %x.biased.highbits = and <2 x i4> %x.biased, <i4 -4, i4 -4>491 call void @use.v2i4(<2 x i4> %x.biased.highbits)492 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i4> %x, <2 x i4> %x.biased.highbits493 ret <2 x i4> %x.roundedup494}495define <2 x i4> @t18_replacement_0b1000(<2 x i4> %x) {496; CHECK-LABEL: @t18_replacement_0b1000(497; CHECK-NEXT: [[X_BIASED:%.*]] = add <2 x i4> [[X:%.*]], splat (i4 3)498; CHECK-NEXT: [[X_BIASED_HIGHBITS:%.*]] = and <2 x i4> [[X_BIASED]], splat (i4 -4)499; CHECK-NEXT: call void @use.v2i4(<2 x i4> [[X_BIASED_HIGHBITS]])500; CHECK-NEXT: ret <2 x i4> [[X_BIASED_HIGHBITS]]501;502 %x.lowbits = and <2 x i4> %x, <i4 3, i4 poison>503 %x.lowbits.are.zero = icmp eq <2 x i4> %x.lowbits, <i4 0, i4 0>504 %x.biased = add <2 x i4> %x, <i4 3, i4 3>505 %x.biased.highbits = and <2 x i4> %x.biased, <i4 -4, i4 -4>506 call void @use.v2i4(<2 x i4> %x.biased.highbits)507 %x.roundedup = select <2 x i1> %x.lowbits.are.zero, <2 x i4> %x, <2 x i4> %x.biased.highbits508 ret <2 x i4> %x.roundedup509}510