226 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 u<= x & C8; Should be transformed into:9; x u<= C10; Iff: isPowerOf2(C + 1)11; C can be 0 and -1.12 13declare i8 @gen8()14declare <2 x i8> @gen2x8()15declare <3 x i8> @gen3x8()16 17; ============================================================================ ;18; Basic positive tests19; ============================================================================ ;20 21define i1 @p0() {22; CHECK-LABEL: @p0(23; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()24; CHECK-NEXT: [[RET:%.*]] = icmp ult i8 [[X]], 425; CHECK-NEXT: ret i1 [[RET]]26;27 %x = call i8 @gen8()28 %tmp0 = and i8 %x, 329 %ret = icmp ule i8 %x, %tmp030 ret i1 %ret31}32 33define i1 @pv(i8 %y) {34; CHECK-LABEL: @pv(35; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()36; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]37; CHECK-NEXT: [[RET:%.*]] = icmp ule i8 [[X]], [[TMP0]]38; CHECK-NEXT: ret i1 [[RET]]39;40 %x = call i8 @gen8()41 %tmp0 = lshr i8 -1, %y42 %tmp1 = and i8 %tmp0, %x43 %ret = icmp ule i8 %x, %tmp144 ret i1 %ret45}46 47; ============================================================================ ;48; Vector tests49; ============================================================================ ;50 51define <2 x i1> @p1_vec_splat() {52; CHECK-LABEL: @p1_vec_splat(53; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()54; CHECK-NEXT: [[RET:%.*]] = icmp ult <2 x i8> [[X]], splat (i8 4)55; CHECK-NEXT: ret <2 x i1> [[RET]]56;57 %x = call <2 x i8> @gen2x8()58 %tmp0 = and <2 x i8> %x, <i8 3, i8 3>59 %ret = icmp ule <2 x i8> %x, %tmp060 ret <2 x i1> %ret61}62 63define <2 x i1> @p2_vec_nonsplat() {64; CHECK-LABEL: @p2_vec_nonsplat(65; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()66; CHECK-NEXT: [[RET:%.*]] = icmp ult <2 x i8> [[X]], <i8 4, i8 16>67; CHECK-NEXT: ret <2 x i1> [[RET]]68;69 %x = call <2 x i8> @gen2x8()70 %tmp0 = and <2 x i8> %x, <i8 3, i8 15> ; doesn't have to be splat.71 %ret = icmp ule <2 x i8> %x, %tmp072 ret <2 x i1> %ret73}74 75define <2 x i1> @p2_vec_nonsplat_edgecase0() {76; CHECK-LABEL: @p2_vec_nonsplat_edgecase0(77; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()78; CHECK-NEXT: [[RET:%.*]] = icmp ult <2 x i8> [[X]], <i8 4, i8 1>79; CHECK-NEXT: ret <2 x i1> [[RET]]80;81 %x = call <2 x i8> @gen2x8()82 %tmp0 = and <2 x i8> %x, <i8 3, i8 0>83 %ret = icmp ule <2 x i8> %x, %tmp084 ret <2 x i1> %ret85}86define <2 x i1> @p2_vec_nonsplat_edgecase1() {87; CHECK-LABEL: @p2_vec_nonsplat_edgecase1(88; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()89; CHECK-NEXT: [[RET:%.*]] = icmp ule <2 x i8> [[X]], <i8 3, i8 -1>90; CHECK-NEXT: ret <2 x i1> [[RET]]91;92 %x = call <2 x i8> @gen2x8()93 %tmp0 = and <2 x i8> %x, <i8 3, i8 -1>94 %ret = icmp ule <2 x i8> %x, %tmp095 ret <2 x i1> %ret96}97 98define <3 x i1> @p3_vec_splat_poison() {99; CHECK-LABEL: @p3_vec_splat_poison(100; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8()101; CHECK-NEXT: [[RET:%.*]] = icmp ult <3 x i8> [[X]], splat (i8 4)102; CHECK-NEXT: ret <3 x i1> [[RET]]103;104 %x = call <3 x i8> @gen3x8()105 %tmp0 = and <3 x i8> %x, <i8 3, i8 poison, i8 3>106 %ret = icmp ule <3 x i8> %x, %tmp0107 ret <3 x i1> %ret108}109 110; ============================================================================ ;111; Commutativity tests.112; ============================================================================ ;113 114define i1 @c0(i8 %x) {115; CHECK-LABEL: @c0(116; CHECK-NEXT: ret i1 true117;118 %tmp0 = and i8 %x, 3119 %ret = icmp ule i8 %tmp0, %x ; swapped order120 ret i1 %ret121}122 123; ============================================================================ ;124; Commutativity tests with variable125; ============================================================================ ;126 127define i1 @cv0(i8 %y) {128; CHECK-LABEL: @cv0(129; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()130; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]131; CHECK-NEXT: [[RET:%.*]] = icmp ule i8 [[X]], [[TMP0]]132; CHECK-NEXT: ret i1 [[RET]]133;134 %x = call i8 @gen8()135 %tmp0 = lshr i8 -1, %y136 %tmp1 = and i8 %tmp0, %x ; swapped order137 %ret = icmp ule i8 %x, %tmp1138 ret i1 %ret139}140 141define i1 @cv1(i8 %y) {142; CHECK-LABEL: @cv1(143; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()144; CHECK-NEXT: ret i1 true145;146 %x = call i8 @gen8()147 %tmp0 = lshr i8 -1, %y148 %tmp1 = and i8 %x, %tmp0149 %ret = icmp ule i8 %tmp1, %x ; swapped order150 ret i1 %ret151}152 153define i1 @cv2(i8 %x, i8 %y) {154; CHECK-LABEL: @cv2(155; CHECK-NEXT: ret i1 true156;157 %tmp0 = lshr i8 -1, %y158 %tmp1 = and i8 %tmp0, %x ; swapped order159 %ret = icmp ule i8 %tmp1, %x ; swapped order160 ret i1 %ret161}162 163; ============================================================================ ;164; One-use tests. We don't care about multi-uses here.165; ============================================================================ ;166 167declare void @use8(i8)168 169define i1 @oneuse0() {170; CHECK-LABEL: @oneuse0(171; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()172; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 3173; CHECK-NEXT: call void @use8(i8 [[TMP0]])174; CHECK-NEXT: [[RET:%.*]] = icmp ult i8 [[X]], 4175; CHECK-NEXT: ret i1 [[RET]]176;177 %x = call i8 @gen8()178 %tmp0 = and i8 %x, 3179 call void @use8(i8 %tmp0)180 %ret = icmp ule i8 %x, %tmp0181 ret i1 %ret182}183 184; ============================================================================ ;185; Negative tests186; ============================================================================ ;187 188define i1 @n0() {189; CHECK-LABEL: @n0(190; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()191; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], -5192; CHECK-NEXT: [[RET:%.*]] = icmp eq i8 [[TMP1]], 0193; CHECK-NEXT: ret i1 [[RET]]194;195 %x = call i8 @gen8()196 %tmp0 = and i8 %x, 4 ; power-of-two, but invalid.197 %ret = icmp ule i8 %x, %tmp0198 ret i1 %ret199}200 201define i1 @n1(i8 %y, i8 %notx) {202; CHECK-LABEL: @n1(203; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()204; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 3205; CHECK-NEXT: [[RET:%.*]] = icmp ule i8 [[TMP0]], [[NOTX:%.*]]206; CHECK-NEXT: ret i1 [[RET]]207;208 %x = call i8 @gen8()209 %tmp0 = and i8 %x, 3210 %ret = icmp ule i8 %tmp0, %notx ; not %x211 ret i1 %ret212}213 214define <2 x i1> @n2() {215; CHECK-LABEL: @n2(216; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()217; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X]], <i8 -4, i8 -17>218; CHECK-NEXT: [[RET:%.*]] = icmp eq <2 x i8> [[TMP1]], zeroinitializer219; CHECK-NEXT: ret <2 x i1> [[RET]]220;221 %x = call <2 x i8> @gen2x8()222 %tmp0 = and <2 x i8> %x, <i8 3, i8 16> ; only the first one is valid.223 %ret = icmp ule <2 x i8> %x, %tmp0224 ret <2 x i1> %ret225}226