221 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4; https://bugs.llvm.org/show_bug.cgi?id=381235 6; Pattern:7; x & C != x8; Should be transformed into:9; x u> C10; Iff: isPowerOf2(C + 1)11; C can be 0 and -1.12 13; ============================================================================ ;14; Basic positive tests15; ============================================================================ ;16 17define i1 @p0(i8 %x) {18; CHECK-LABEL: @p0(19; CHECK-NEXT: [[RET:%.*]] = icmp ugt i8 [[X:%.*]], 320; CHECK-NEXT: ret i1 [[RET]]21;22 %tmp0 = and i8 %x, 323 %ret = icmp ne i8 %tmp0, %x24 ret i1 %ret25}26 27define i1 @pv(i8 %x, i8 %y) {28; CHECK-LABEL: @pv(29; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]30; CHECK-NEXT: [[RET:%.*]] = icmp ugt i8 [[X:%.*]], [[TMP0]]31; CHECK-NEXT: ret i1 [[RET]]32;33 %tmp0 = lshr i8 -1, %y34 %tmp1 = and i8 %tmp0, %x35 %ret = icmp ne i8 %tmp1, %x36 ret i1 %ret37}38 39; ============================================================================ ;40; Vector tests41; ============================================================================ ;42 43define <2 x i1> @p1_vec_splat(<2 x i8> %x) {44; CHECK-LABEL: @p1_vec_splat(45; CHECK-NEXT: [[RET:%.*]] = icmp ugt <2 x i8> [[X:%.*]], splat (i8 3)46; CHECK-NEXT: ret <2 x i1> [[RET]]47;48 %tmp0 = and <2 x i8> %x, <i8 3, i8 3>49 %ret = icmp ne <2 x i8> %tmp0, %x50 ret <2 x i1> %ret51}52 53define <2 x i1> @p2_vec_nonsplat(<2 x i8> %x) {54; CHECK-LABEL: @p2_vec_nonsplat(55; CHECK-NEXT: [[RET:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 3, i8 15>56; CHECK-NEXT: ret <2 x i1> [[RET]]57;58 %tmp0 = and <2 x i8> %x, <i8 3, i8 15> ; doesn't have to be splat.59 %ret = icmp ne <2 x i8> %tmp0, %x60 ret <2 x i1> %ret61}62 63define <2 x i1> @p2_vec_nonsplat_edgecase0(<2 x i8> %x) {64; CHECK-LABEL: @p2_vec_nonsplat_edgecase0(65; CHECK-NEXT: [[RET:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 3, i8 0>66; CHECK-NEXT: ret <2 x i1> [[RET]]67;68 %tmp0 = and <2 x i8> %x, <i8 3, i8 0>69 %ret = icmp ne <2 x i8> %tmp0, %x70 ret <2 x i1> %ret71}72define <2 x i1> @p2_vec_nonsplat_edgecase1(<2 x i8> %x) {73; CHECK-LABEL: @p2_vec_nonsplat_edgecase1(74; CHECK-NEXT: [[RET:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 3, i8 -1>75; CHECK-NEXT: ret <2 x i1> [[RET]]76;77 %tmp0 = and <2 x i8> %x, <i8 3, i8 -1>78 %ret = icmp ne <2 x i8> %tmp0, %x79 ret <2 x i1> %ret80}81 82define <3 x i1> @p3_vec_splat_poison(<3 x i8> %x) {83; CHECK-LABEL: @p3_vec_splat_poison(84; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X:%.*]], <i8 3, i8 poison, i8 3>85; CHECK-NEXT: ret <3 x i1> [[RET]]86;87 %tmp0 = and <3 x i8> %x, <i8 3, i8 poison, i8 3>88 %ret = icmp ne <3 x i8> %tmp0, %x89 ret <3 x i1> %ret90}91 92define <3 x i1> @p3_vec_nonsplat_poison(<3 x i8> %x) {93; CHECK-LABEL: @p3_vec_nonsplat_poison(94; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X:%.*]], <i8 -1, i8 poison, i8 3>95; CHECK-NEXT: ret <3 x i1> [[RET]]96;97 %tmp0 = and <3 x i8> %x, <i8 -1, i8 poison, i8 3>98 %ret = icmp ne <3 x i8> %tmp0, %x99 ret <3 x i1> %ret100}101 102; ============================================================================ ;103; Commutativity tests.104; ============================================================================ ;105 106declare i8 @gen8()107 108define i1 @c0() {109; CHECK-LABEL: @c0(110; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()111; CHECK-NEXT: [[RET:%.*]] = icmp ugt i8 [[X]], 3112; CHECK-NEXT: ret i1 [[RET]]113;114 %x = call i8 @gen8()115 %tmp0 = and i8 %x, 3116 %ret = icmp ne i8 %x, %tmp0 ; swapped order117 ret i1 %ret118}119 120; ============================================================================ ;121; Commutativity tests with variable122; ============================================================================ ;123 124define i1 @cv0(i8 %y) {125; CHECK-LABEL: @cv0(126; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()127; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]128; CHECK-NEXT: [[RET:%.*]] = icmp ugt i8 [[X]], [[TMP0]]129; CHECK-NEXT: ret i1 [[RET]]130;131 %x = call i8 @gen8()132 %tmp0 = lshr i8 -1, %y133 %tmp1 = and i8 %x, %tmp0 ; swapped order134 %ret = icmp ne i8 %tmp1, %x135 ret i1 %ret136}137 138define i1 @cv1(i8 %y) {139; CHECK-LABEL: @cv1(140; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()141; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]142; CHECK-NEXT: [[RET:%.*]] = icmp ugt i8 [[X]], [[TMP0]]143; CHECK-NEXT: ret i1 [[RET]]144;145 %x = call i8 @gen8()146 %tmp0 = lshr i8 -1, %y147 %tmp1 = and i8 %tmp0, %x148 %ret = icmp ne i8 %x, %tmp1 ; swapped order149 ret i1 %ret150}151 152define i1 @cv2(i8 %y) {153; CHECK-LABEL: @cv2(154; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()155; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]156; CHECK-NEXT: [[RET:%.*]] = icmp ugt i8 [[X]], [[TMP0]]157; CHECK-NEXT: ret i1 [[RET]]158;159 %x = call i8 @gen8()160 %tmp0 = lshr i8 -1, %y161 %tmp1 = and i8 %x, %tmp0 ; swapped order162 %ret = icmp ne i8 %x, %tmp1 ; swapped order163 ret i1 %ret164}165 166; ============================================================================ ;167; One-use tests. We don't care about multi-uses here.168; ============================================================================ ;169 170declare void @use8(i8)171 172define i1 @oneuse0(i8 %x) {173; CHECK-LABEL: @oneuse0(174; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 3175; CHECK-NEXT: call void @use8(i8 [[TMP0]])176; CHECK-NEXT: [[RET:%.*]] = icmp ugt i8 [[X]], 3177; CHECK-NEXT: ret i1 [[RET]]178;179 %tmp0 = and i8 %x, 3180 call void @use8(i8 %tmp0)181 %ret = icmp ne i8 %tmp0, %x182 ret i1 %ret183}184 185; ============================================================================ ;186; Negative tests187; ============================================================================ ;188 189define i1 @n0(i8 %x) {190; CHECK-LABEL: @n0(191; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -5192; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[TMP1]], 0193; CHECK-NEXT: ret i1 [[RET]]194;195 %tmp0 = and i8 %x, 4 ; power-of-two, but invalid.196 %ret = icmp ne i8 %tmp0, %x197 ret i1 %ret198}199 200define i1 @n1(i8 %x, i8 %y, i8 %notx) {201; CHECK-LABEL: @n1(202; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 3203; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[TMP0]], [[NOTX:%.*]]204; CHECK-NEXT: ret i1 [[RET]]205;206 %tmp0 = and i8 %x, 3207 %ret = icmp ne i8 %tmp0, %notx ; not %x208 ret i1 %ret209}210 211define <2 x i1> @n2(<2 x i8> %x) {212; CHECK-LABEL: @n2(213; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X:%.*]], <i8 -4, i8 -17>214; CHECK-NEXT: [[RET:%.*]] = icmp ne <2 x i8> [[TMP1]], zeroinitializer215; CHECK-NEXT: ret <2 x i1> [[RET]]216;217 %tmp0 = and <2 x i8> %x, <i8 3, i8 16> ; only the first one is valid.218 %ret = icmp ne <2 x i8> %tmp0, %x219 ret <2 x i1> %ret220}221