Skip to content

Commit

Permalink
[InstCombine] add multi-use tests for shl folds; NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
rotateright committed Sep 28, 2021
1 parent 595c418 commit 6c1a58f
Showing 1 changed file with 140 additions and 0 deletions.
140 changes: 140 additions & 0 deletions llvm/test/Transforms/InstCombine/shl-bo.ll
@@ -1,6 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s

declare void @use(i8)

define i8 @lshr_add(i8 %a, i8 %y) {
; CHECK-LABEL: @lshr_add(
; CHECK-NEXT: [[X:%.*]] = srem i8 [[A:%.*]], 42
Expand Down Expand Up @@ -149,6 +151,36 @@ define <2 x i8> @lshr_xor_commute_splat(<2 x i8> %a, <2 x i8> %y) {
ret <2 x i8> %l
}

define i8 @lshr_add_use1(i8 %x, i8 %y) {
; CHECK-LABEL: @lshr_add_use1(
; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 5
; CHECK-NEXT: call void @use(i8 [[R]])
; CHECK-NEXT: [[B:%.*]] = add i8 [[R]], [[X:%.*]]
; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 5
; CHECK-NEXT: ret i8 [[L]]
;
%r = lshr i8 %y, 5
call void @use(i8 %r)
%b = add i8 %r, %x
%l = shl i8 %b, 5
ret i8 %l
}

define i8 @lshr_add_use2(i8 %x, i8 %y) {
; CHECK-LABEL: @lshr_add_use2(
; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 5
; CHECK-NEXT: [[B:%.*]] = add i8 [[R]], [[X:%.*]]
; CHECK-NEXT: call void @use(i8 [[B]])
; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 5
; CHECK-NEXT: ret i8 [[L]]
;
%r = lshr i8 %y, 5
%b = add i8 %r, %x
call void @use(i8 %b)
%l = shl i8 %b, 5
ret i8 %l
}

define i8 @lshr_and_add(i8 %a, i8 %y) {
; CHECK-LABEL: @lshr_and_add(
; CHECK-NEXT: [[X:%.*]] = srem i8 [[A:%.*]], 42
Expand Down Expand Up @@ -310,6 +342,114 @@ define <2 x i8> @lshr_and_xor_commute_splat(<2 x i8> %a, <2 x i8> %y) {
ret <2 x i8> %l
}

define i8 @lshr_and_add_use1(i8 %x, i8 %y) {
; CHECK-LABEL: @lshr_and_add_use1(
; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 3
; CHECK-NEXT: call void @use(i8 [[R]])
; CHECK-NEXT: [[M:%.*]] = and i8 [[R]], 12
; CHECK-NEXT: [[B:%.*]] = add i8 [[M]], [[X:%.*]]
; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 3
; CHECK-NEXT: ret i8 [[L]]
;
%r = lshr i8 %y, 3
call void @use(i8 %r)
%m = and i8 %r, 12
%b = add i8 %x, %m
%l = shl i8 %b, 3
ret i8 %l
}

define i8 @lshr_and_add_use2(i8 %x, i8 %y) {
; CHECK-LABEL: @lshr_and_add_use2(
; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 3
; CHECK-NEXT: [[M:%.*]] = and i8 [[R]], 12
; CHECK-NEXT: call void @use(i8 [[M]])
; CHECK-NEXT: [[B:%.*]] = add i8 [[M]], [[X:%.*]]
; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 3
; CHECK-NEXT: ret i8 [[L]]
;
%r = lshr i8 %y, 3
%m = and i8 %r, 12
call void @use(i8 %m)
%b = add i8 %x, %m
%l = shl i8 %b, 3
ret i8 %l
}

define i8 @lshr_and_add_use3(i8 %x, i8 %y) {
; CHECK-LABEL: @lshr_and_add_use3(
; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 3
; CHECK-NEXT: [[M:%.*]] = and i8 [[R]], 12
; CHECK-NEXT: [[B:%.*]] = add i8 [[M]], [[X:%.*]]
; CHECK-NEXT: call void @use(i8 [[B]])
; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 3
; CHECK-NEXT: ret i8 [[L]]
;
%r = lshr i8 %y, 3
%m = and i8 %r, 12
%b = add i8 %x, %m
call void @use(i8 %b)
%l = shl i8 %b, 3
ret i8 %l
}

define i8 @lshr_and_add_use4(i8 %x, i8 %y) {
; CHECK-LABEL: @lshr_and_add_use4(
; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 3
; CHECK-NEXT: call void @use(i8 [[R]])
; CHECK-NEXT: [[M:%.*]] = and i8 [[R]], 12
; CHECK-NEXT: call void @use(i8 [[M]])
; CHECK-NEXT: [[B:%.*]] = add i8 [[M]], [[X:%.*]]
; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 3
; CHECK-NEXT: ret i8 [[L]]
;
%r = lshr i8 %y, 3
call void @use(i8 %r)
%m = and i8 %r, 12
call void @use(i8 %m)
%b = add i8 %x, %m
%l = shl i8 %b, 3
ret i8 %l
}

define i8 @lshr_and_add_use5(i8 %x, i8 %y) {
; CHECK-LABEL: @lshr_and_add_use5(
; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 3
; CHECK-NEXT: [[M:%.*]] = and i8 [[R]], 12
; CHECK-NEXT: call void @use(i8 [[M]])
; CHECK-NEXT: [[B:%.*]] = add i8 [[M]], [[X:%.*]]
; CHECK-NEXT: call void @use(i8 [[B]])
; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 3
; CHECK-NEXT: ret i8 [[L]]
;
%r = lshr i8 %y, 3
%m = and i8 %r, 12
call void @use(i8 %m)
%b = add i8 %x, %m
call void @use(i8 %b)
%l = shl i8 %b, 3
ret i8 %l
}

define i8 @lshr_and_add_use6(i8 %x, i8 %y) {
; CHECK-LABEL: @lshr_and_add_use6(
; CHECK-NEXT: [[R:%.*]] = lshr i8 [[Y:%.*]], 3
; CHECK-NEXT: call void @use(i8 [[R]])
; CHECK-NEXT: [[M:%.*]] = and i8 [[R]], 12
; CHECK-NEXT: call void @use(i8 [[M]])
; CHECK-NEXT: [[B:%.*]] = add i8 [[M]], [[X:%.*]]
; CHECK-NEXT: [[L:%.*]] = shl i8 [[B]], 3
; CHECK-NEXT: ret i8 [[L]]
;
%r = lshr i8 %y, 3
call void @use(i8 %r)
%m = and i8 %r, 12
call void @use(i8 %m)
%b = add i8 %x, %m
%l = shl i8 %b, 3
ret i8 %l
}

define <2 x i8> @lshr_add_shl_v2i8_undef(<2 x i8> %x, <2 x i8> %y) {
; CHECK-LABEL: @lshr_add_shl_v2i8_undef(
; CHECK-NEXT: [[A:%.*]] = lshr <2 x i8> [[Y:%.*]], <i8 5, i8 undef>
Expand Down

0 comments on commit 6c1a58f

Please sign in to comment.