[llvm] ac76945 - [InstSimplify] add tests for or-of-shifted-one-bits; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 24 12:38:45 PDT 2021
Author: Sanjay Patel
Date: 2021-08-24T15:38:38-04:00
New Revision: ac7694596dc5fe114b029384c2d87e6b49549116
URL: https://github.com/llvm/llvm-project/commit/ac7694596dc5fe114b029384c2d87e6b49549116
DIFF: https://github.com/llvm/llvm-project/commit/ac7694596dc5fe114b029384c2d87e6b49549116.diff
LOG: [InstSimplify] add tests for or-of-shifted-one-bits; NFC
Added:
Modified:
llvm/test/Transforms/InstSimplify/or.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstSimplify/or.ll b/llvm/test/Transforms/InstSimplify/or.ll
index a91aeeb504b58..45bfafe54ffa6 100644
--- a/llvm/test/Transforms/InstSimplify/or.ll
+++ b/llvm/test/Transforms/InstSimplify/or.ll
@@ -445,3 +445,93 @@ define i32 @and_or_not_or8(i32 %A, i32 %B) {
%i5 = or i32 %i4, %i2
ret i32 %i5
}
+
+define i32 @shifted_all_ones(i32 %shamt) {
+; CHECK-LABEL: @shifted_all_ones(
+; CHECK-NEXT: [[R:%.*]] = lshr i32 -1, [[SHAMT:%.*]]
+; CHECK-NEXT: [[S:%.*]] = sub i32 32, [[SHAMT]]
+; CHECK-NEXT: [[L:%.*]] = shl i32 -1, [[S]]
+; CHECK-NEXT: [[O:%.*]] = or i32 [[R]], [[L]]
+; CHECK-NEXT: ret i32 [[O]]
+;
+ %r = lshr i32 -1, %shamt
+ %s = sub i32 32, %shamt
+ %l = shl i32 -1, %s
+ %o = or i32 %r, %l
+ ret i32 %o
+}
+
+define i32 @shifted_all_ones_commute(i32 %shamt) {
+; CHECK-LABEL: @shifted_all_ones_commute(
+; CHECK-NEXT: [[R:%.*]] = lshr i32 -1, [[SHAMT:%.*]]
+; CHECK-NEXT: [[S:%.*]] = sub i32 31, [[SHAMT]]
+; CHECK-NEXT: [[L:%.*]] = shl i32 -1, [[S]]
+; CHECK-NEXT: [[O:%.*]] = or i32 [[L]], [[R]]
+; CHECK-NEXT: ret i32 [[O]]
+;
+ %r = lshr i32 -1, %shamt
+ %s = sub i32 31, %shamt
+ %l = shl i32 -1, %s
+ %o = or i32 %l, %r
+ ret i32 %o
+}
+
+define <2 x i9> @shifted_all_ones_sub_on_lshr(<2 x i9> %shamt) {
+; CHECK-LABEL: @shifted_all_ones_sub_on_lshr(
+; CHECK-NEXT: [[L:%.*]] = shl <2 x i9> <i9 -1, i9 -1>, [[SHAMT:%.*]]
+; CHECK-NEXT: [[S:%.*]] = sub <2 x i9> <i9 5, i9 5>, [[SHAMT]]
+; CHECK-NEXT: [[R:%.*]] = lshr <2 x i9> <i9 -1, i9 -1>, [[S]]
+; CHECK-NEXT: [[O:%.*]] = or <2 x i9> [[L]], [[R]]
+; CHECK-NEXT: ret <2 x i9> [[O]]
+;
+ %l = shl <2 x i9> <i9 -1, i9 -1>, %shamt
+ %s = sub <2 x i9> <i9 5, i9 5>, %shamt
+ %r = lshr <2 x i9> <i9 -1, i9 -1>, %s
+ %o = or <2 x i9> %l, %r
+ ret <2 x i9> %o
+}
+
+define i8 @shifted_all_ones_sub_on_lshr_commute(i8 %shamt) {
+; CHECK-LABEL: @shifted_all_ones_sub_on_lshr_commute(
+; CHECK-NEXT: [[L:%.*]] = shl i8 -1, [[SHAMT:%.*]]
+; CHECK-NEXT: [[S:%.*]] = sub i8 8, [[SHAMT]]
+; CHECK-NEXT: [[R:%.*]] = lshr i8 -1, [[S]]
+; CHECK-NEXT: [[O:%.*]] = or i8 [[R]], [[L]]
+; CHECK-NEXT: ret i8 [[O]]
+;
+ %l = shl i8 -1, %shamt
+ %s = sub i8 8, %shamt
+ %r = lshr i8 -1, %s
+ %o = or i8 %r, %l
+ ret i8 %o
+}
+
+define i32 @shifted_not_all_ones(i32 %shamt) {
+; CHECK-LABEL: @shifted_not_all_ones(
+; CHECK-NEXT: [[R:%.*]] = lshr i32 -2, [[SHAMT:%.*]]
+; CHECK-NEXT: [[S:%.*]] = sub i32 31, [[SHAMT]]
+; CHECK-NEXT: [[L:%.*]] = shl i32 -1, [[S]]
+; CHECK-NEXT: [[O:%.*]] = or i32 [[R]], [[L]]
+; CHECK-NEXT: ret i32 [[O]]
+;
+ %r = lshr i32 -2, %shamt
+ %s = sub i32 31, %shamt
+ %l = shl i32 -1, %s
+ %o = or i32 %r, %l
+ ret i32 %o
+}
+
+define i32 @shifted_all_ones_greater_than_bitwidth(i32 %shamt) {
+; CHECK-LABEL: @shifted_all_ones_greater_than_bitwidth(
+; CHECK-NEXT: [[R:%.*]] = lshr i32 -1, [[SHAMT:%.*]]
+; CHECK-NEXT: [[S:%.*]] = sub i32 33, [[SHAMT]]
+; CHECK-NEXT: [[L:%.*]] = shl i32 -1, [[S]]
+; CHECK-NEXT: [[O:%.*]] = or i32 [[R]], [[L]]
+; CHECK-NEXT: ret i32 [[O]]
+;
+ %r = lshr i32 -1, %shamt
+ %s = sub i32 33, %shamt
+ %l = shl i32 -1, %s
+ %o = or i32 %r, %l
+ ret i32 %o
+}
More information about the llvm-commits
mailing list