|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 |
| 2 | +; RUN: opt -passes=instcombine -S < %s | FileCheck %s |
| 3 | + |
| 4 | +define i32 @test_compute_sign_bits() { |
| 5 | +; CHECK-LABEL: define i32 @test_compute_sign_bits() { |
| 6 | +; CHECK-NEXT: [[ENTRY:.*:]] |
| 7 | +; CHECK-NEXT: ret i32 -1 |
| 8 | +; |
| 9 | +entry: |
| 10 | + %a = add i8 -1, 0 |
| 11 | + %b = bitcast i8 %a to <4 x i2> |
| 12 | + %c = ashr <4 x i2> %b, <i2 1, i2 1, i2 1, i2 1> |
| 13 | + %d = bitcast <4 x i2> %c to i8 |
| 14 | + %e = sext i8 %d to i32 |
| 15 | + ret i32 %e |
| 16 | +} |
| 17 | + |
| 18 | +; Test with sign extension to ensure proper sign bit tracking |
| 19 | +define <4 x i2> @test_sext_bitcast(<1 x i8> %a0, <1 x i8> %a1) { |
| 20 | +; CHECK-LABEL: define <4 x i2> @test_sext_bitcast( |
| 21 | +; CHECK-SAME: <1 x i8> [[A0:%.*]], <1 x i8> [[A1:%.*]]) { |
| 22 | +; CHECK-NEXT: [[ENTRY:.*:]] |
| 23 | +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <1 x i8> [[A0]], [[A1]] |
| 24 | +; CHECK-NEXT: [[EXT:%.*]] = sext <1 x i1> [[CMP]] to <1 x i8> |
| 25 | +; CHECK-NEXT: [[SUB:%.*]] = bitcast <1 x i8> [[EXT]] to <4 x i2> |
| 26 | +; CHECK-NEXT: [[RESULT:%.*]] = ashr <4 x i2> [[SUB]], splat (i2 1) |
| 27 | +; CHECK-NEXT: ret <4 x i2> [[RESULT]] |
| 28 | +; |
| 29 | +entry: |
| 30 | + %cmp = icmp sgt <1 x i8> %a0, %a1 |
| 31 | + %ext = sext <1 x i1> %cmp to <1 x i8> |
| 32 | + %sub = bitcast <1 x i8> %ext to <4 x i2> |
| 33 | + %result = ashr <4 x i2> %sub, <i2 1, i2 1, i2 1, i2 1> |
| 34 | + ret <4 x i2> %result |
| 35 | +} |
0 commit comments