Skip to content

Commit

Permalink
[InstCombine] add tests for shl-of-sub; NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
rotateright committed Sep 27, 2021
1 parent 06e2a06 commit b75ed24
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion llvm/test/Transforms/InstCombine/shl-sub.ll
@@ -1,6 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -instcombine -S < %s | FileCheck %s

declare void @use(i32)

define i32 @shl_sub_i32(i32 %x) {
; CHECK-LABEL: @shl_sub_i32(
; CHECK-NEXT: [[R:%.*]] = lshr i32 -2147483648, [[X:%.*]]
Expand Down Expand Up @@ -176,5 +178,37 @@ define <3 x i64> @shl_sub_i64_vec_undef_bad2(<3 x i64> %x) {
ret <3 x i64> %r
}

define i32 @shl_const_op1_sub_const_op0(i32 %x) {
; CHECK-LABEL: @shl_const_op1_sub_const_op0(
; CHECK-NEXT: [[S_NEG:%.*]] = mul i32 [[X:%.*]], -8
; CHECK-NEXT: [[R:%.*]] = add i32 [[S_NEG]], 336
; CHECK-NEXT: ret i32 [[R]]
;
%s = sub i32 42, %x
%r = shl i32 %s, 3
ret i32 %r
}

declare void @use(i32)
define <2 x i32> @shl_const_op1_sub_const_op0_splat(<2 x i32> %x) {
; CHECK-LABEL: @shl_const_op1_sub_const_op0_splat(
; CHECK-NEXT: [[S_NEG:%.*]] = mul <2 x i32> [[X:%.*]], <i32 -8, i32 -8>
; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[S_NEG]], <i32 336, i32 336>
; CHECK-NEXT: ret <2 x i32> [[R]]
;
%s = sub <2 x i32> <i32 42, i32 42>, %x
%r = shl <2 x i32> %s, <i32 3, i32 3>
ret <2 x i32> %r
}

define i32 @shl_const_op1_sub_const_op0_use(i32 %x) {
; CHECK-LABEL: @shl_const_op1_sub_const_op0_use(
; CHECK-NEXT: [[S:%.*]] = sub i32 42, [[X:%.*]]
; CHECK-NEXT: call void @use(i32 [[S]])
; CHECK-NEXT: [[R:%.*]] = shl i32 [[S]], 3
; CHECK-NEXT: ret i32 [[R]]
;
%s = sub i32 42, %x
call void @use(i32 %s)
%r = shl i32 %s, 3
ret i32 %r
}

0 comments on commit b75ed24

Please sign in to comment.