|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | +; RUN: opt -instcombine -S < %s | FileCheck %s |
| 3 | + |
| 4 | +define i16 @sext_shl_trunc_same_size(i16 %x, i32 %y) { |
| 5 | +; CHECK-LABEL: @sext_shl_trunc_same_size( |
| 6 | +; CHECK-NEXT: [[CONV:%.*]] = sext i16 [[X:%.*]] to i32 |
| 7 | +; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[CONV]], [[Y:%.*]] |
| 8 | +; CHECK-NEXT: [[T:%.*]] = trunc i32 [[SHL]] to i16 |
| 9 | +; CHECK-NEXT: ret i16 [[T]] |
| 10 | +; |
| 11 | + %conv = sext i16 %x to i32 |
| 12 | + %shl = shl i32 %conv, %y |
| 13 | + %t = trunc i32 %shl to i16 |
| 14 | + ret i16 %t |
| 15 | +} |
| 16 | + |
| 17 | +define i5 @sext_shl_trunc_smaller(i16 %x, i32 %y) { |
| 18 | +; CHECK-LABEL: @sext_shl_trunc_smaller( |
| 19 | +; CHECK-NEXT: [[CONV:%.*]] = sext i16 [[X:%.*]] to i32 |
| 20 | +; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[CONV]], [[Y:%.*]] |
| 21 | +; CHECK-NEXT: [[T:%.*]] = trunc i32 [[SHL]] to i5 |
| 22 | +; CHECK-NEXT: ret i5 [[T]] |
| 23 | +; |
| 24 | + %conv = sext i16 %x to i32 |
| 25 | + %shl = shl i32 %conv, %y |
| 26 | + %t = trunc i32 %shl to i5 |
| 27 | + ret i5 %t |
| 28 | +} |
| 29 | + |
| 30 | +define i17 @sext_shl_trunc_larger(i16 %x, i32 %y) { |
| 31 | +; CHECK-LABEL: @sext_shl_trunc_larger( |
| 32 | +; CHECK-NEXT: [[CONV:%.*]] = sext i16 [[X:%.*]] to i32 |
| 33 | +; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[CONV]], [[Y:%.*]] |
| 34 | +; CHECK-NEXT: [[T:%.*]] = trunc i32 [[SHL]] to i17 |
| 35 | +; CHECK-NEXT: ret i17 [[T]] |
| 36 | +; |
| 37 | + %conv = sext i16 %x to i32 |
| 38 | + %shl = shl i32 %conv, %y |
| 39 | + %t = trunc i32 %shl to i17 |
| 40 | + ret i17 %t |
| 41 | +} |
| 42 | + |
| 43 | +define i32 @sext_shl_mask(i16 %x, i32 %y) { |
| 44 | +; CHECK-LABEL: @sext_shl_mask( |
| 45 | +; CHECK-NEXT: [[CONV:%.*]] = sext i16 [[X:%.*]] to i32 |
| 46 | +; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[CONV]], [[Y:%.*]] |
| 47 | +; CHECK-NEXT: [[T:%.*]] = and i32 [[SHL]], 65535 |
| 48 | +; CHECK-NEXT: ret i32 [[T]] |
| 49 | +; |
| 50 | + %conv = sext i16 %x to i32 |
| 51 | + %shl = shl i32 %conv, %y |
| 52 | + %t = and i32 %shl, 65535 |
| 53 | + ret i32 %t |
| 54 | +} |
| 55 | + |
| 56 | +define i32 @sext_shl_mask_higher(i16 %x, i32 %y) { |
| 57 | +; CHECK-LABEL: @sext_shl_mask_higher( |
| 58 | +; CHECK-NEXT: [[CONV:%.*]] = sext i16 [[X:%.*]] to i32 |
| 59 | +; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[CONV]], [[Y:%.*]] |
| 60 | +; CHECK-NEXT: [[T:%.*]] = and i32 [[SHL]], 65536 |
| 61 | +; CHECK-NEXT: ret i32 [[T]] |
| 62 | +; |
| 63 | + %conv = sext i16 %x to i32 |
| 64 | + %shl = shl i32 %conv, %y |
| 65 | + %t = and i32 %shl, 65536 |
| 66 | + ret i32 %t |
| 67 | +} |
| 68 | + |
| 69 | +define i32 @set_shl_mask(i32 %x, i32 %y) { |
| 70 | +; CHECK-LABEL: @set_shl_mask( |
| 71 | +; CHECK-NEXT: [[Z:%.*]] = or i32 [[X:%.*]], 196609 |
| 72 | +; CHECK-NEXT: [[S:%.*]] = shl i32 [[Z]], [[Y:%.*]] |
| 73 | +; CHECK-NEXT: [[R:%.*]] = and i32 [[S]], 65536 |
| 74 | +; CHECK-NEXT: ret i32 [[R]] |
| 75 | +; |
| 76 | + %z = or i32 %x, 196609 |
| 77 | + %s = shl i32 %z, %y |
| 78 | + %r = and i32 %s, 65536 |
| 79 | + ret i32 %r |
| 80 | +} |
0 commit comments