From 8937450e8581a8a135c61ff083828e6603755ef5 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 3 Jun 2021 15:53:11 -0400 Subject: [PATCH] [InstCombine] add tests for sext-of-trunc-of-lshr; NFC --- .../InstCombine/lshr-trunc-sext-to-ashr-sext.ll | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/lshr-trunc-sext-to-ashr-sext.ll b/llvm/test/Transforms/InstCombine/lshr-trunc-sext-to-ashr-sext.ll index 174bbcb..1333833 100644 --- a/llvm/test/Transforms/InstCombine/lshr-trunc-sext-to-ashr-sext.ll +++ b/llvm/test/Transforms/InstCombine/lshr-trunc-sext-to-ashr-sext.ll @@ -5,6 +5,7 @@ ; but no other bits, then we can instead do signed shift, and signext it. ; Note that we can replace trunc with trunc of new signed shift. +declare void @use32(i32) declare void @use8(i8) declare void @use4(i4) declare void @usevec8(<2 x i8>) @@ -176,3 +177,86 @@ define <2 x i16> @t11_extrause2_vec_undef(<2 x i8> %x) { %c = sext <2 x i4> %b to <2 x i16> ret <2 x i16> %c } + +define <2 x i10> @wide_source_shifted_signbit(<2 x i32> %x) { +; CHECK-LABEL: @wide_source_shifted_signbit( +; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], +; CHECK-NEXT: [[B:%.*]] = trunc <2 x i32> [[A]] to <2 x i8> +; CHECK-NEXT: [[C:%.*]] = sext <2 x i8> [[B]] to <2 x i10> +; CHECK-NEXT: ret <2 x i10> [[C]] +; + %a = lshr <2 x i32> %x, + %b = trunc <2 x i32> %a to <2 x i8> + %c = sext <2 x i8> %b to <2 x i10> + ret <2 x i10> %c +} + +define i10 @wide_source_shifted_signbit_use1(i32 %x) { +; CHECK-LABEL: @wide_source_shifted_signbit_use1( +; CHECK-NEXT: [[A:%.*]] = lshr i32 [[X:%.*]], 24 +; CHECK-NEXT: call void @use32(i32 [[A]]) +; CHECK-NEXT: [[B:%.*]] = trunc i32 [[A]] to i8 +; CHECK-NEXT: [[C:%.*]] = sext i8 [[B]] to i10 +; CHECK-NEXT: ret i10 [[C]] +; + %a = lshr i32 %x, 24 + call void @use32(i32 %a) + %b = trunc i32 %a to i8 + %c = sext i8 %b to i10 + ret i10 %c +} + +define i10 @wide_source_shifted_signbit_use2(i32 %x) { +; CHECK-LABEL: @wide_source_shifted_signbit_use2( +; CHECK-NEXT: [[A:%.*]] = lshr i32 [[X:%.*]], 24 +; CHECK-NEXT: [[B:%.*]] = trunc i32 [[A]] to i8 +; CHECK-NEXT: call void @use8(i8 [[B]]) +; CHECK-NEXT: [[C:%.*]] = sext i8 [[B]] to i10 +; CHECK-NEXT: ret i10 [[C]] +; + %a = lshr i32 %x, 24 + %b = trunc i32 %a to i8 + call void @use8(i8 %b) + %c = sext i8 %b to i10 + ret i10 %c +} + +define i32 @same_source_shifted_signbit(i32 %x) { +; CHECK-LABEL: @same_source_shifted_signbit( +; CHECK-NEXT: [[C:%.*]] = ashr i32 [[X:%.*]], 24 +; CHECK-NEXT: ret i32 [[C]] +; + %a = lshr i32 %x, 24 + %b = trunc i32 %a to i8 + %c = sext i8 %b to i32 + ret i32 %c +} + +define i32 @same_source_shifted_signbit_use1(i32 %x) { +; CHECK-LABEL: @same_source_shifted_signbit_use1( +; CHECK-NEXT: [[A:%.*]] = lshr i32 [[X:%.*]], 24 +; CHECK-NEXT: call void @use32(i32 [[A]]) +; CHECK-NEXT: [[C:%.*]] = ashr i32 [[X]], 24 +; CHECK-NEXT: ret i32 [[C]] +; + %a = lshr i32 %x, 24 + call void @use32(i32 %a) + %b = trunc i32 %a to i8 + %c = sext i8 %b to i32 + ret i32 %c +} + +define i32 @same_source_shifted_signbit_use2(i32 %x) { +; CHECK-LABEL: @same_source_shifted_signbit_use2( +; CHECK-NEXT: [[A:%.*]] = lshr i32 [[X:%.*]], 24 +; CHECK-NEXT: [[B:%.*]] = trunc i32 [[A]] to i8 +; CHECK-NEXT: call void @use8(i8 [[B]]) +; CHECK-NEXT: [[C:%.*]] = sext i8 [[B]] to i32 +; CHECK-NEXT: ret i32 [[C]] +; + %a = lshr i32 %x, 24 + %b = trunc i32 %a to i8 + call void @use8(i8 %b) + %c = sext i8 %b to i32 + ret i32 %c +} -- 2.7.4