[llvm] 40b637f - [InstCombine] Add tests for indirect mul by power of 2; NFC
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 7 12:58:34 PDT 2023
Author: Noah Goldstein
Date: 2023-04-07T14:58:15-05:00
New Revision: 40b637f4604666c1388cbb5f19de55ead536a248
URL: https://github.com/llvm/llvm-project/commit/40b637f4604666c1388cbb5f19de55ead536a248
DIFF: https://github.com/llvm/llvm-project/commit/40b637f4604666c1388cbb5f19de55ead536a248.diff
LOG: [InstCombine] Add tests for indirect mul by power of 2; NFC
Differential Revision: https://reviews.llvm.org/D146346
Added:
llvm/test/Transforms/InstCombine/mul-pow2.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/mul-pow2.ll b/llvm/test/Transforms/InstCombine/mul-pow2.ll
new file mode 100644
index 0000000000000..58dd6a23c076e
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/mul-pow2.ll
@@ -0,0 +1,104 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=instcombine -S < %s | FileCheck %s
+declare void @use_i8(i8)
+define i8 @mul_selectp2_x(i8 %x, i1 %c) {
+; CHECK-LABEL: @mul_selectp2_x(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C:%.*]], i8 2, i8 4
+; CHECK-NEXT: [[R:%.*]] = mul i8 [[S]], [[X:%.*]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %s = select i1 %c, i8 2, i8 4
+ %r = mul i8 %s, %x
+ ret i8 %r
+}
+
+
+define i8 @mul_selectp2_x_propegate_nuw(i8 %x, i1 %c) {
+; CHECK-LABEL: @mul_selectp2_x_propegate_nuw(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C:%.*]], i8 2, i8 4
+; CHECK-NEXT: [[R:%.*]] = mul nuw nsw i8 [[S]], [[X:%.*]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %s = select i1 %c, i8 2, i8 4
+ %r = mul nuw nsw i8 %s, %x
+ ret i8 %r
+}
+
+
+define i8 @mul_selectp2_x_multiuse_fixme(i8 %x, i1 %c) {
+; CHECK-LABEL: @mul_selectp2_x_multiuse_fixme(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C:%.*]], i8 2, i8 4
+; CHECK-NEXT: [[R:%.*]] = mul i8 [[S]], [[X:%.*]]
+; CHECK-NEXT: call void @use_i8(i8 [[S]])
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %s = select i1 %c, i8 2, i8 4
+ %r = mul i8 %s, %x
+ call void @use_i8(i8 %s)
+ ret i8 %r
+}
+
+define i8 @mul_selectp2_x_non_const(i8 %x, i1 %c, i8 %yy) {
+; CHECK-LABEL: @mul_selectp2_x_non_const(
+; CHECK-NEXT: [[Y:%.*]] = shl nuw i8 1, [[YY:%.*]]
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C:%.*]], i8 2, i8 [[Y]]
+; CHECK-NEXT: [[R:%.*]] = mul i8 [[S]], [[X:%.*]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %y = shl i8 1, %yy
+ %s = select i1 %c, i8 2, i8 %y
+ %r = mul i8 %s, %x
+ ret i8 %r
+}
+
+define i8 @mul_selectp2_x_non_const_multiuse(i8 %x, i1 %c, i8 %yy) {
+; CHECK-LABEL: @mul_selectp2_x_non_const_multiuse(
+; CHECK-NEXT: [[Y:%.*]] = shl nuw i8 1, [[YY:%.*]]
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C:%.*]], i8 2, i8 [[Y]]
+; CHECK-NEXT: [[R:%.*]] = mul i8 [[S]], [[X:%.*]]
+; CHECK-NEXT: call void @use_i8(i8 [[Y]])
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %y = shl i8 1, %yy
+ %s = select i1 %c, i8 2, i8 %y
+ %r = mul i8 %s, %x
+ call void @use_i8(i8 %y)
+ ret i8 %r
+}
+
+define i8 @mul_x_selectp2(i8 %xx, i1 %c) {
+; CHECK-LABEL: @mul_x_selectp2(
+; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], [[XX]]
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C:%.*]], i8 8, i8 1
+; CHECK-NEXT: [[R:%.*]] = mul i8 [[X]], [[S]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %x = mul i8 %xx, %xx
+ %s = select i1 %c, i8 8, i8 1
+ %r = mul i8 %x, %s
+ ret i8 %r
+}
+
+define i8 @mul_select_nonp2_x_fail(i8 %x, i1 %c) {
+; CHECK-LABEL: @mul_select_nonp2_x_fail(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C:%.*]], i8 2, i8 5
+; CHECK-NEXT: [[R:%.*]] = mul i8 [[S]], [[X:%.*]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %s = select i1 %c, i8 2, i8 5
+ %r = mul i8 %s, %x
+ ret i8 %r
+}
+
+define <2 x i8> @mul_x_selectp2_vec(<2 x i8> %xx, i1 %c) {
+; CHECK-LABEL: @mul_x_selectp2_vec(
+; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[XX:%.*]], [[XX]]
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C:%.*]], <2 x i8> <i8 8, i8 16>, <2 x i8> <i8 4, i8 1>
+; CHECK-NEXT: [[R:%.*]] = mul <2 x i8> [[X]], [[S]]
+; CHECK-NEXT: ret <2 x i8> [[R]]
+;
+ %x = mul <2 x i8> %xx, %xx
+ %s = select i1 %c, <2 x i8> <i8 8, i8 16>, <2 x i8> <i8 4, i8 1>
+ %r = mul <2 x i8> %x, %s
+ ret <2 x i8> %r
+}
More information about the llvm-commits
mailing list