[llvm] 782d010 - [InstCombine] add tests for C << (X - C1); NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 21 08:39:46 PDT 2022


Author: Sanjay Patel
Date: 2022-04-21T11:38:26-04:00
New Revision: 782d0105ba245aaded586931a997618a25f80690

URL: https://github.com/llvm/llvm-project/commit/782d0105ba245aaded586931a997618a25f80690
DIFF: https://github.com/llvm/llvm-project/commit/782d0105ba245aaded586931a997618a25f80690.diff

LOG: [InstCombine] add tests for C << (X - C1); NFC

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/shift-add.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/shift-add.ll b/llvm/test/Transforms/InstCombine/shift-add.ll
index f75f6a95f8f8a..141551978377e 100644
--- a/llvm/test/Transforms/InstCombine/shift-add.ll
+++ b/llvm/test/Transforms/InstCombine/shift-add.ll
@@ -169,3 +169,51 @@ define i32 @shl_add_nsw(i32 %x) {
   %r = shl i32 6, %a
   ret i32 %r
 }
+
+; PR54890
+
+define i32 @shl_nsw_add_negative(i32 %x) {
+; CHECK-LABEL: @shl_nsw_add_negative(
+; CHECK-NEXT:    [[A:%.*]] = add i32 [[X:%.*]], -1
+; CHECK-NEXT:    [[R:%.*]] = shl nsw i32 2, [[A]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %a = add i32 %x, -1
+  %r = shl nsw i32 2, %a
+  ret i32 %r
+}
+
+define <2 x i8> @shl_nuw_add_negative_splat_uses(<2 x i8> %x, <2 x i8>* %p) {
+; CHECK-LABEL: @shl_nuw_add_negative_splat_uses(
+; CHECK-NEXT:    [[A:%.*]] = add <2 x i8> [[X:%.*]], <i8 -2, i8 -2>
+; CHECK-NEXT:    store <2 x i8> [[A]], <2 x i8>* [[P:%.*]], align 2
+; CHECK-NEXT:    [[R:%.*]] = shl nuw <2 x i8> <i8 12, i8 12>, [[A]]
+; CHECK-NEXT:    ret <2 x i8> [[R]]
+;
+  %a = add <2 x i8> %x, <i8 -2, i8 -2>
+  store <2 x i8> %a, <2 x i8>* %p
+  %r = shl nuw <2 x i8> <i8 12, i8 12>, %a
+  ret <2 x i8> %r
+}
+
+define i32 @shl_nsw_add_negative_invalid_constant(i32 %x) {
+; CHECK-LABEL: @shl_nsw_add_negative_invalid_constant(
+; CHECK-NEXT:    [[A:%.*]] = add i32 [[X:%.*]], -2
+; CHECK-NEXT:    [[R:%.*]] = shl nsw i32 2, [[A]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %a = add i32 %x, -2
+  %r = shl nsw i32 2, %a
+  ret i32 %r
+}
+
+define i32 @shl_nsw_add_positive_invalid_constant(i32 %x) {
+; CHECK-LABEL: @shl_nsw_add_positive_invalid_constant(
+; CHECK-NEXT:    [[A:%.*]] = add i32 [[X:%.*]], 2
+; CHECK-NEXT:    [[R:%.*]] = shl nsw i32 4, [[A]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %a = add i32 %x, 2
+  %r = shl nsw i32 4, %a
+  ret i32 %r
+}


        


More information about the llvm-commits mailing list