|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | +; RUN: opt -passes=instcombine -S < %s | FileCheck %s |
| 3 | + |
| 4 | +; If we only want bits that already match the signbit then we don't need to shift. |
| 5 | + |
| 6 | +define i32 @srem2_ashr_mask(i32 %a0) { |
| 7 | +; CHECK-LABEL: @srem2_ashr_mask( |
| 8 | +; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A0:%.*]], -2147483647 |
| 9 | +; CHECK-NEXT: [[ISNEG:%.*]] = icmp eq i32 [[TMP1]], -2147483647 |
| 10 | +; CHECK-NEXT: [[MASK:%.*]] = select i1 [[ISNEG]], i32 2, i32 0 |
| 11 | +; CHECK-NEXT: ret i32 [[MASK]] |
| 12 | +; |
| 13 | + %srem = srem i32 %a0, 2 ; result = (1,0,-1) num signbits = 31 |
| 14 | + %ashr = ashr i32 %srem, 31 |
| 15 | + %mask = and i32 %ashr, 2 |
| 16 | + ret i32 %mask |
| 17 | +} |
| 18 | + |
| 19 | +define i32 @srem8_ashr_mask(i32 %a0) { |
| 20 | +; CHECK-LABEL: @srem8_ashr_mask( |
| 21 | +; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A0:%.*]], -2147483641 |
| 22 | +; CHECK-NEXT: [[ISNEG:%.*]] = icmp ugt i32 [[TMP1]], -2147483648 |
| 23 | +; CHECK-NEXT: [[MASK:%.*]] = select i1 [[ISNEG]], i32 2, i32 0 |
| 24 | +; CHECK-NEXT: ret i32 [[MASK]] |
| 25 | +; |
| 26 | + %srem = srem i32 %a0, 8 |
| 27 | + %ashr = ashr i32 %srem, 31 |
| 28 | + %mask = and i32 %ashr, 2 |
| 29 | + ret i32 %mask |
| 30 | +} |
| 31 | + |
| 32 | +define <2 x i32> @srem2_ashr_mask_vector(<2 x i32> %a0) { |
| 33 | +; CHECK-LABEL: @srem2_ashr_mask_vector( |
| 34 | +; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[A0:%.*]], <i32 -2147483647, i32 -2147483647> |
| 35 | +; CHECK-NEXT: [[ISNEG:%.*]] = icmp eq <2 x i32> [[TMP1]], <i32 -2147483647, i32 -2147483647> |
| 36 | +; CHECK-NEXT: [[MASK:%.*]] = select <2 x i1> [[ISNEG]], <2 x i32> <i32 2, i32 2>, <2 x i32> zeroinitializer |
| 37 | +; CHECK-NEXT: ret <2 x i32> [[MASK]] |
| 38 | +; |
| 39 | + %srem = srem <2 x i32> %a0, <i32 2, i32 2> |
| 40 | + %ashr = ashr <2 x i32> %srem, <i32 31, i32 31> |
| 41 | + %mask = and <2 x i32> %ashr, <i32 2, i32 2> |
| 42 | + ret <2 x i32> %mask |
| 43 | +} |
| 44 | + |
| 45 | +define <2 x i32> @srem2_ashr_mask_vector_nonconstant(<2 x i32> %a0, <2 x i32> %a1) { |
| 46 | +; CHECK-LABEL: @srem2_ashr_mask_vector_nonconstant( |
| 47 | +; CHECK-NEXT: [[SREM:%.*]] = srem <2 x i32> [[A0:%.*]], <i32 2, i32 2> |
| 48 | +; CHECK-NEXT: [[ASHR:%.*]] = ashr <2 x i32> [[SREM]], [[A1:%.*]] |
| 49 | +; CHECK-NEXT: [[MASK:%.*]] = and <2 x i32> [[ASHR]], <i32 2, i32 2> |
| 50 | +; CHECK-NEXT: ret <2 x i32> [[MASK]] |
| 51 | +; |
| 52 | + %srem = srem <2 x i32> %a0, <i32 2, i32 2> |
| 53 | + %ashr = ashr <2 x i32> %srem, %a1 |
| 54 | + %mask = and <2 x i32> %ashr, <i32 2, i32 2> |
| 55 | + ret <2 x i32> %mask |
| 56 | +} |
0 commit comments