diff options
3 files changed, 176 insertions, 4 deletions
diff --git a/llvm/test/Transforms/InstCombine/canonicalize-ashr-shl-to-masking.ll b/llvm/test/Transforms/InstCombine/canonicalize-ashr-shl-to-masking.ll index e70a6f73227..73b630543ef 100644 --- a/llvm/test/Transforms/InstCombine/canonicalize-ashr-shl-to-masking.ll +++ b/llvm/test/Transforms/InstCombine/canonicalize-ashr-shl-to-masking.ll @@ -98,8 +98,8 @@ define i32 @positive_biggershl_ashrexact(i32 %x) { ret i32 %ret } -define i32 @positive_biggershl_ashrexact_shlexact(i32 %x) { -; CHECK-LABEL: @positive_biggershl_ashrexact_shlexact( +define i32 @positive_biggershl_ashrexact_shlnuw(i32 %x) { +; CHECK-LABEL: @positive_biggershl_ashrexact_shlnuw( ; CHECK-NEXT: [[RET:%.*]] = shl nuw i32 [[X:%.*]], 5 ; CHECK-NEXT: ret i32 [[RET]] ; @@ -259,6 +259,50 @@ define <3 x i32> @positive_biggershl_vec_undef2(<3 x i32> %x) { } ; ============================================================================ ; +; Positive multi-use tests with constant +; ============================================================================ ; + +; FIXME: drop 'exact' once it is no longer needed. + +define i32 @positive_sameconst_multiuse(i32 %x) { +; CHECK-LABEL: @positive_sameconst_multiuse( +; CHECK-NEXT: [[TMP0:%.*]] = ashr exact i32 [[X:%.*]], 5 +; CHECK-NEXT: call void @use32(i32 [[TMP0]]) +; CHECK-NEXT: ret i32 [[X]] +; + %tmp0 = ashr exact i32 %x, 5 + call void @use32(i32 %tmp0) + %ret = shl i32 %tmp0, 5 + ret i32 %ret +} + +define i32 @positive_biggerashr_multiuse(i32 %x) { +; CHECK-LABEL: @positive_biggerashr_multiuse( +; CHECK-NEXT: [[TMP0:%.*]] = ashr exact i32 [[X:%.*]], 10 +; CHECK-NEXT: call void @use32(i32 [[TMP0]]) +; CHECK-NEXT: [[RET:%.*]] = ashr exact i32 [[X]], 5 +; CHECK-NEXT: ret i32 [[RET]] +; + %tmp0 = ashr exact i32 %x, 10 + call void @use32(i32 %tmp0) + %ret = shl i32 %tmp0, 5 + ret i32 %ret +} + +define i32 @positive_biggershl_multiuse(i32 %x) { +; CHECK-LABEL: @positive_biggershl_multiuse( +; CHECK-NEXT: [[TMP0:%.*]] = ashr exact i32 [[X:%.*]], 5 +; CHECK-NEXT: call void @use32(i32 [[TMP0]]) +; CHECK-NEXT: [[RET:%.*]] = shl i32 [[X]], 5 +; CHECK-NEXT: ret i32 [[RET]] +; + %tmp0 = ashr exact i32 %x, 5 + call void @use32(i32 %tmp0) + %ret = shl i32 %tmp0, 10 + ret i32 %ret +} + +; ============================================================================ ; ; Constant Non-Splat Vectors ; ============================================================================ ; diff --git a/llvm/test/Transforms/InstCombine/canonicalize-lshr-shl-to-masking.ll b/llvm/test/Transforms/InstCombine/canonicalize-lshr-shl-to-masking.ll index c6730aaa5e0..092c80c2d0a 100644 --- a/llvm/test/Transforms/InstCombine/canonicalize-lshr-shl-to-masking.ll +++ b/llvm/test/Transforms/InstCombine/canonicalize-lshr-shl-to-masking.ll @@ -98,8 +98,8 @@ define i32 @positive_biggershl_lshrexact(i32 %x) { ret i32 %ret } -define i32 @positive_biggershl_lshrexact_shlexact(i32 %x) { -; CHECK-LABEL: @positive_biggershl_lshrexact_shlexact( +define i32 @positive_biggershl_lshrexact_shlnuw(i32 %x) { +; CHECK-LABEL: @positive_biggershl_lshrexact_shlnuw( ; CHECK-NEXT: [[RET:%.*]] = shl nuw i32 [[X:%.*]], 5 ; CHECK-NEXT: ret i32 [[RET]] ; @@ -259,6 +259,50 @@ define <3 x i32> @positive_biggershl_vec_undef2(<3 x i32> %x) { } ; ============================================================================ ; +; Positive multi-use tests with constant +; ============================================================================ ; + +; FIXME: drop 'exact' once it is no longer needed. + +define i32 @positive_sameconst_multiuse(i32 %x) { +; CHECK-LABEL: @positive_sameconst_multiuse( +; CHECK-NEXT: [[TMP0:%.*]] = lshr exact i32 [[X:%.*]], 5 +; CHECK-NEXT: call void @use32(i32 [[TMP0]]) +; CHECK-NEXT: ret i32 [[X]] +; + %tmp0 = lshr exact i32 %x, 5 + call void @use32(i32 %tmp0) + %ret = shl i32 %tmp0, 5 + ret i32 %ret +} + +define i32 @positive_biggerlshr_multiuse(i32 %x) { +; CHECK-LABEL: @positive_biggerlshr_multiuse( +; CHECK-NEXT: [[TMP0:%.*]] = lshr exact i32 [[X:%.*]], 10 +; CHECK-NEXT: call void @use32(i32 [[TMP0]]) +; CHECK-NEXT: [[RET:%.*]] = lshr exact i32 [[X]], 5 +; CHECK-NEXT: ret i32 [[RET]] +; + %tmp0 = lshr exact i32 %x, 10 + call void @use32(i32 %tmp0) + %ret = shl i32 %tmp0, 5 + ret i32 %ret +} + +define i32 @positive_biggershl_multiuse(i32 %x) { +; CHECK-LABEL: @positive_biggershl_multiuse( +; CHECK-NEXT: [[TMP0:%.*]] = lshr exact i32 [[X:%.*]], 5 +; CHECK-NEXT: call void @use32(i32 [[TMP0]]) +; CHECK-NEXT: [[RET:%.*]] = shl i32 [[X]], 5 +; CHECK-NEXT: ret i32 [[RET]] +; + %tmp0 = lshr exact i32 %x, 5 + call void @use32(i32 %tmp0) + %ret = shl i32 %tmp0, 10 + ret i32 %ret +} + +; ============================================================================ ; ; Constant Non-Splat Vectors ; ============================================================================ ; diff --git a/llvm/test/Transforms/InstCombine/canonicalize-shl-lshr-to-masking.ll b/llvm/test/Transforms/InstCombine/canonicalize-shl-lshr-to-masking.ll index 10a9a10dfda..81af5a7979e 100644 --- a/llvm/test/Transforms/InstCombine/canonicalize-shl-lshr-to-masking.ll +++ b/llvm/test/Transforms/InstCombine/canonicalize-shl-lshr-to-masking.ll @@ -55,6 +55,17 @@ define i32 @positive_biggerLshr(i32 %x) { ret i32 %ret } +define i32 @positive_biggerLshr_lshrexact(i32 %x) { +; CHECK-LABEL: @positive_biggerLshr_lshrexact( +; CHECK-NEXT: [[TMP1:%.*]] = lshr exact i32 [[X:%.*]], 5 +; CHECK-NEXT: [[RET:%.*]] = and i32 [[TMP1]], 4194303 +; CHECK-NEXT: ret i32 [[RET]] +; + %tmp0 = shl i32 %x, 5 + %ret = lshr exact i32 %tmp0, 10 + ret i32 %ret +} + ; ============================================================================ ; ; NUW on the first shift ; ============================================================================ ; @@ -258,6 +269,79 @@ define <3 x i32> @positive_biggerLshr_vec_undef2(<3 x i32> %x) { } ; ============================================================================ ; +; Positive multi-use tests with constant +; ============================================================================ ; + +define i32 @positive_sameconst_multiuse(i32 %x) { +; CHECK-LABEL: @positive_sameconst_multiuse( +; CHECK-NEXT: [[TMP0:%.*]] = shl i32 [[X:%.*]], 5 +; CHECK-NEXT: call void @use32(i32 [[TMP0]]) +; CHECK-NEXT: [[RET:%.*]] = and i32 [[X]], 134217727 +; CHECK-NEXT: ret i32 [[RET]] +; + %tmp0 = shl i32 %x, 5 + call void @use32(i32 %tmp0) + %ret = lshr i32 %tmp0, 5 + ret i32 %ret +} + +define i32 @positive_biggerShl_shlnuw_multiuse(i32 %x) { +; CHECK-LABEL: @positive_biggerShl_shlnuw_multiuse( +; CHECK-NEXT: [[TMP0:%.*]] = shl nuw i32 [[X:%.*]], 10 +; CHECK-NEXT: call void @use32(i32 [[TMP0]]) +; CHECK-NEXT: [[RET:%.*]] = shl nuw i32 [[X]], 5 +; CHECK-NEXT: ret i32 [[RET]] +; + %tmp0 = shl nuw i32 %x, 10 + call void @use32(i32 %tmp0) + %ret = lshr i32 %tmp0, 5 + ret i32 %ret +} + +define i32 @positive_biggerLshr_shlnuw_multiuse(i32 %x) { +; CHECK-LABEL: @positive_biggerLshr_shlnuw_multiuse( +; CHECK-NEXT: [[TMP0:%.*]] = shl nuw i32 [[X:%.*]], 5 +; CHECK-NEXT: call void @use32(i32 [[TMP0]]) +; CHECK-NEXT: [[RET:%.*]] = lshr i32 [[X]], 5 +; CHECK-NEXT: ret i32 [[RET]] +; + %tmp0 = shl nuw i32 %x, 5 + call void @use32(i32 %tmp0) + %ret = lshr i32 %tmp0, 10 + ret i32 %ret +} + +; NOTE: creates one extra instruction, but this seems intentional. +define i32 @positive_biggerShl_multiuse_extrainstr(i32 %x) { +; CHECK-LABEL: @positive_biggerShl_multiuse_extrainstr( +; CHECK-NEXT: [[TMP0:%.*]] = shl i32 [[X:%.*]], 10 +; CHECK-NEXT: call void @use32(i32 [[TMP0]]) +; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X]], 5 +; CHECK-NEXT: [[RET:%.*]] = and i32 [[TMP1]], 134217696 +; CHECK-NEXT: ret i32 [[RET]] +; + %tmp0 = shl i32 %x, 10 + call void @use32(i32 %tmp0) + %ret = lshr i32 %tmp0, 5 + ret i32 %ret +} + +; NOTE: creates one extra instruction, but this seems intentional. +define i32 @positive_biggerLshr_multiuse_extrainstr(i32 %x) { +; CHECK-LABEL: @positive_biggerLshr_multiuse_extrainstr( +; CHECK-NEXT: [[TMP0:%.*]] = shl i32 [[X:%.*]], 5 +; CHECK-NEXT: call void @use32(i32 [[TMP0]]) +; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X]], 5 +; CHECK-NEXT: [[RET:%.*]] = and i32 [[TMP1]], 4194303 +; CHECK-NEXT: ret i32 [[RET]] +; + %tmp0 = shl i32 %x, 5 + call void @use32(i32 %tmp0) + %ret = lshr i32 %tmp0, 10 + ret i32 %ret +} + +; ============================================================================ ; ; Constant Non-Splat Vectors ; ============================================================================ ; |