[llvm] 6c1a58f - [InstCombine] add multi-use tests for shl folds; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 28 14:12:41 PDT 2021
Author: Sanjay Patel
Date: 2021-09-28T17:06:45-04:00
New Revision: 6c1a58fe51bc41e28371132380ccd4a8cd2e3e11
URL: https://github.com/llvm/llvm-project/commit/6c1a58fe51bc41e28371132380ccd4a8cd2e3e11
DIFF: https://github.com/llvm/llvm-project/commit/6c1a58fe51bc41e28371132380ccd4a8cd2e3e11.diff
LOG: [InstCombine] add multi-use tests for shl folds; NFC
Added:
Modified:
llvm/test/Transforms/InstCombine/shl-bo.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/shl-bo.ll b/llvm/test/Transforms/InstCombine/shl-bo.ll
index f581ca2cb628..2ac2211f5ab2 100644
--- a/llvm/test/Transforms/InstCombine/shl-bo.ll
+++ b/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
@@ -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
@@ -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>
More information about the llvm-commits
mailing list