[llvm] 8937450 - [InstCombine] add tests for sext-of-trunc-of-lshr; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 4 04:04:46 PDT 2021
Author: Sanjay Patel
Date: 2021-06-04T07:04:37-04:00
New Revision: 8937450e8581a8a135c61ff083828e6603755ef5
URL: https://github.com/llvm/llvm-project/commit/8937450e8581a8a135c61ff083828e6603755ef5
DIFF: https://github.com/llvm/llvm-project/commit/8937450e8581a8a135c61ff083828e6603755ef5.diff
LOG: [InstCombine] add tests for sext-of-trunc-of-lshr; NFC
Added:
Modified:
llvm/test/Transforms/InstCombine/lshr-trunc-sext-to-ashr-sext.ll
Removed:
################################################################################
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 174bbcb088b17..1333833976432 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:%.*]], <i32 24, i32 24>
+; 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, <i32 24, i32 24>
+ %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
+}
More information about the llvm-commits
mailing list