brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.5 KiB · 12aa836 Raw
247 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 & ((-1 << y) >> y) == x8; Should be transformed into:9;   x u<= ((-1 << y) >> y)10 11; This pattern is uncanonical, but we can not canonicalize it due to extra uses.12 13declare void @use8(i8)14declare void @use2i8(<2 x i8>)15declare void @use3i8(<3 x i8>)16 17; ============================================================================ ;18; Basic positive tests19; ============================================================================ ;20 21define i1 @p0(i8 %x, i8 %y) {22; CHECK-LABEL: @p0(23; CHECK-NEXT:    [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]24; CHECK-NEXT:    call void @use8(i8 [[T0]])25; CHECK-NEXT:    [[T1:%.*]] = lshr i8 -1, [[Y]]26; CHECK-NEXT:    [[RET:%.*]] = icmp ule i8 [[X:%.*]], [[T1]]27; CHECK-NEXT:    ret i1 [[RET]]28;29  %t0 = shl i8 -1, %y30  call void @use8(i8 %t0)31  %t1 = lshr i8 %t0, %y32  %t2 = and i8 %t1, %x33  %ret = icmp eq i8 %t2, %x34  ret i1 %ret35}36 37; ============================================================================ ;38; Vector tests39; ============================================================================ ;40 41define <2 x i1> @p1_vec(<2 x i8> %x, <2 x i8> %y) {42; CHECK-LABEL: @p1_vec(43; CHECK-NEXT:    [[T0:%.*]] = shl nsw <2 x i8> splat (i8 -1), [[Y:%.*]]44; CHECK-NEXT:    call void @use2i8(<2 x i8> [[T0]])45; CHECK-NEXT:    [[T1:%.*]] = lshr <2 x i8> splat (i8 -1), [[Y]]46; CHECK-NEXT:    [[RET:%.*]] = icmp ule <2 x i8> [[X:%.*]], [[T1]]47; CHECK-NEXT:    ret <2 x i1> [[RET]]48;49  %t0 = shl <2 x i8> <i8 -1, i8 -1>, %y50  call void @use2i8(<2 x i8> %t0)51  %t1 = lshr <2 x i8> %t0, %y52  %t2 = and <2 x i8> %t1, %x53  %ret = icmp eq <2 x i8> %t2, %x54  ret <2 x i1> %ret55}56 57define <3 x i1> @p2_vec_poison0(<3 x i8> %x, <3 x i8> %y) {58; CHECK-LABEL: @p2_vec_poison0(59; CHECK-NEXT:    [[T0:%.*]] = shl nsw <3 x i8> <i8 -1, i8 poison, i8 -1>, [[Y:%.*]]60; CHECK-NEXT:    call void @use3i8(<3 x i8> [[T0]])61; CHECK-NEXT:    [[T1:%.*]] = lshr <3 x i8> splat (i8 -1), [[Y]]62; CHECK-NEXT:    [[RET:%.*]] = icmp ule <3 x i8> [[X:%.*]], [[T1]]63; CHECK-NEXT:    ret <3 x i1> [[RET]]64;65  %t0 = shl <3 x i8> <i8 -1, i8 poison, i8 -1>, %y66  call void @use3i8(<3 x i8> %t0)67  %t1 = lshr <3 x i8> %t0, %y68  %t2 = and <3 x i8> %t1, %x69  %ret = icmp eq <3 x i8> %t2, %x70  ret <3 x i1> %ret71}72 73; ============================================================================ ;74; Commutativity tests.75; ============================================================================ ;76 77declare i8 @gen8()78 79define i1 @c0(i8 %y) {80; CHECK-LABEL: @c0(81; CHECK-NEXT:    [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]82; CHECK-NEXT:    call void @use8(i8 [[T0]])83; CHECK-NEXT:    [[T1:%.*]] = lshr i8 -1, [[Y]]84; CHECK-NEXT:    [[X:%.*]] = call i8 @gen8()85; CHECK-NEXT:    [[RET:%.*]] = icmp ule i8 [[X]], [[T1]]86; CHECK-NEXT:    ret i1 [[RET]]87;88  %t0 = shl i8 -1, %y89  call void @use8(i8 %t0)90  %t1 = lshr i8 %t0, %y91  %x = call i8 @gen8()92  %t2 = and i8 %x, %t1 ; swapped order93  %ret = icmp eq i8 %t2, %x94  ret i1 %ret95}96 97define i1 @c1(i8 %y) {98; CHECK-LABEL: @c1(99; CHECK-NEXT:    [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]100; CHECK-NEXT:    call void @use8(i8 [[T0]])101; CHECK-NEXT:    [[T1:%.*]] = lshr i8 -1, [[Y]]102; CHECK-NEXT:    [[X:%.*]] = call i8 @gen8()103; CHECK-NEXT:    [[RET:%.*]] = icmp ule i8 [[X]], [[T1]]104; CHECK-NEXT:    ret i1 [[RET]]105;106  %t0 = shl i8 -1, %y107  call void @use8(i8 %t0)108  %t1 = lshr i8 %t0, %y109  %x = call i8 @gen8()110  %t2 = and i8 %t1, %x111  %ret = icmp eq i8 %x, %t2 ; swapped order112  ret i1 %ret113}114 115define i1 @c2(i8 %y) {116; CHECK-LABEL: @c2(117; CHECK-NEXT:    [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]118; CHECK-NEXT:    call void @use8(i8 [[T0]])119; CHECK-NEXT:    [[T1:%.*]] = lshr i8 -1, [[Y]]120; CHECK-NEXT:    [[X:%.*]] = call i8 @gen8()121; CHECK-NEXT:    [[RET:%.*]] = icmp ule i8 [[X]], [[T1]]122; CHECK-NEXT:    ret i1 [[RET]]123;124  %t0 = shl i8 -1, %y125  call void @use8(i8 %t0)126  %t1 = lshr i8 %t0, %y127  %x = call i8 @gen8()128  %t2 = and i8 %x, %t1 ; swapped order129  %ret = icmp eq i8 %x, %t2 ; swapped order130  ret i1 %ret131}132 133; ============================================================================ ;134; One-use tests. We don't care about multi-uses here.135; ============================================================================ ;136 137define i1 @oneuse0(i8 %x, i8 %y) {138; CHECK-LABEL: @oneuse0(139; CHECK-NEXT:    [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]140; CHECK-NEXT:    call void @use8(i8 [[T0]])141; CHECK-NEXT:    [[T1:%.*]] = lshr i8 -1, [[Y]]142; CHECK-NEXT:    call void @use8(i8 [[T1]])143; CHECK-NEXT:    [[RET:%.*]] = icmp ule i8 [[X:%.*]], [[T1]]144; CHECK-NEXT:    ret i1 [[RET]]145;146  %t0 = shl i8 -1, %y147  call void @use8(i8 %t0) ; needed anyway148  %t1 = lshr i8 %t0, %y149  call void @use8(i8 %t1)150  %t2 = and i8 %t1, %x151  %ret = icmp eq i8 %t2, %x152  ret i1 %ret153}154 155define i1 @oneuse1(i8 %x, i8 %y) {156; CHECK-LABEL: @oneuse1(157; CHECK-NEXT:    [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]158; CHECK-NEXT:    call void @use8(i8 [[T0]])159; CHECK-NEXT:    [[T1:%.*]] = lshr i8 -1, [[Y]]160; CHECK-NEXT:    [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]161; CHECK-NEXT:    call void @use8(i8 [[T2]])162; CHECK-NEXT:    [[RET:%.*]] = icmp ule i8 [[X]], [[T1]]163; CHECK-NEXT:    ret i1 [[RET]]164;165  %t0 = shl i8 -1, %y166  call void @use8(i8 %t0) ; needed anyway167  %t1 = lshr i8 %t0, %y168  %t2 = and i8 %t1, %x169  call void @use8(i8 %t2)170  %ret = icmp eq i8 %t2, %x171  ret i1 %ret172}173 174define i1 @oneuse2(i8 %x, i8 %y) {175; CHECK-LABEL: @oneuse2(176; CHECK-NEXT:    [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]177; CHECK-NEXT:    call void @use8(i8 [[T0]])178; CHECK-NEXT:    [[T1:%.*]] = lshr i8 -1, [[Y]]179; CHECK-NEXT:    call void @use8(i8 [[T1]])180; CHECK-NEXT:    [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]181; CHECK-NEXT:    call void @use8(i8 [[T2]])182; CHECK-NEXT:    [[RET:%.*]] = icmp ule i8 [[X]], [[T1]]183; CHECK-NEXT:    ret i1 [[RET]]184;185  %t0 = shl i8 -1, %y186  call void @use8(i8 %t0)187  %t1 = lshr i8 %t0, %y188  call void @use8(i8 %t1)189  %t2 = and i8 %t1, %x190  call void @use8(i8 %t2)191  %ret = icmp eq i8 %t2, %x192  ret i1 %ret193}194 195; ============================================================================ ;196; Negative tests197; ============================================================================ ;198 199define i1 @n0(i8 %x, i8 %y, i8 %notx) {200; CHECK-LABEL: @n0(201; CHECK-NEXT:    [[T0:%.*]] = shl nsw i8 -1, [[Y:%.*]]202; CHECK-NEXT:    call void @use8(i8 [[T0]])203; CHECK-NEXT:    [[T1:%.*]] = lshr i8 -1, [[Y]]204; CHECK-NEXT:    [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]205; CHECK-NEXT:    [[RET:%.*]] = icmp eq i8 [[T2]], [[NOTX:%.*]]206; CHECK-NEXT:    ret i1 [[RET]]207;208  %t0 = shl i8 -1, %y209  call void @use8(i8 %t0)210  %t1 = lshr i8 %t0, %y211  %t2 = and i8 %t1, %x212  %ret = icmp eq i8 %t2, %notx ; not %x213  ret i1 %ret214}215 216define i1 @n1(i8 %x, i8 %y) {217; CHECK-LABEL: @n1(218; CHECK-NEXT:    [[T0:%.*]] = shl nuw i8 1, [[Y:%.*]]219; CHECK-NEXT:    call void @use8(i8 [[T0]])220; CHECK-NEXT:    [[RET:%.*]] = icmp ult i8 [[X:%.*]], 2221; CHECK-NEXT:    ret i1 [[RET]]222;223  %t0 = shl i8 1, %y ; not -1224  call void @use8(i8 %t0)225  %t1 = lshr i8 %t0, %y226  %t2 = and i8 %t1, %x227  %ret = icmp eq i8 %t2, %x228  ret i1 %ret229}230 231define i1 @n2(i8 %x, i8 %y1, i8 %y2) {232; CHECK-LABEL: @n2(233; CHECK-NEXT:    [[T0:%.*]] = shl nsw i8 -1, [[Y1:%.*]]234; CHECK-NEXT:    call void @use8(i8 [[T0]])235; CHECK-NEXT:    [[T1:%.*]] = lshr i8 [[T0]], [[Y2:%.*]]236; CHECK-NEXT:    [[T2:%.*]] = and i8 [[T1]], [[X:%.*]]237; CHECK-NEXT:    [[RET:%.*]] = icmp eq i8 [[T2]], [[X]]238; CHECK-NEXT:    ret i1 [[RET]]239;240  %t0 = shl i8 -1, %y1 ; not %y2241  call void @use8(i8 %t0)242  %t1 = lshr i8 %t0, %y2 ; not %y1243  %t2 = and i8 %t1, %x244  %ret = icmp eq i8 %t2, %x245  ret i1 %ret246}247