[llvm] 4faeb7d - [InstCombine] Add test for missed opportunity to fold 'or' into 'mul' operand. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 15 21:42:46 PST 2023
Author: Craig Topper
Date: 2023-12-15T21:30:29-08:00
New Revision: 4faeb7dbe9a4d35ea3556a319a814fe7c5d6c27c
URL: https://github.com/llvm/llvm-project/commit/4faeb7dbe9a4d35ea3556a319a814fe7c5d6c27c
DIFF: https://github.com/llvm/llvm-project/commit/4faeb7dbe9a4d35ea3556a319a814fe7c5d6c27c.diff
LOG: [InstCombine] Add test for missed opportunity to fold 'or' into 'mul' operand. NFC
We are able to fold
or (mul X, Y), X --> mul X, (add Y, 1) (when the multiply has no common bits with X)
but we miss it if the mul operands are commuted.
Added:
Modified:
llvm/test/Transforms/InstCombine/or.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/or.ll b/llvm/test/Transforms/InstCombine/or.ll
index 8c8aab2bcba6a8..805546099398b4 100644
--- a/llvm/test/Transforms/InstCombine/or.ll
+++ b/llvm/test/Transforms/InstCombine/or.ll
@@ -1511,6 +1511,21 @@ define <2 x i12> @mul_no_common_bits_commute(<2 x i12> %p) {
ret <2 x i12> %r
}
+define i32 @mul_no_common_bits_commute2(i32 %p1, i32 %p2) {
+; CHECK-LABEL: @mul_no_common_bits_commute2(
+; CHECK-NEXT: [[X:%.*]] = and i32 [[P1:%.*]], 7
+; CHECK-NEXT: [[Y:%.*]] = shl i32 [[P2:%.*]], 3
+; CHECK-NEXT: [[M:%.*]] = mul i32 [[Y]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = or disjoint i32 [[M]], [[X]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %x = and i32 %p1, 7
+ %y = shl i32 %p2, 3
+ %m = mul i32 %y, %x
+ %r = or i32 %m, %x
+ ret i32 %r
+}
+
define i32 @mul_no_common_bits_disjoint(i32 %x, i32 %y) {
; CHECK-LABEL: @mul_no_common_bits_disjoint(
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[Y:%.*]], 1
More information about the llvm-commits
mailing list