Skip to content

Commit 4faeb7d

Browse files
committed
[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.
1 parent 7a0fd97 commit 4faeb7d

File tree

1 file changed

+15
-0
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+15
-0
lines changed

llvm/test/Transforms/InstCombine/or.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,21 @@ define <2 x i12> @mul_no_common_bits_commute(<2 x i12> %p) {
15111511
ret <2 x i12> %r
15121512
}
15131513

1514+
define i32 @mul_no_common_bits_commute2(i32 %p1, i32 %p2) {
1515+
; CHECK-LABEL: @mul_no_common_bits_commute2(
1516+
; CHECK-NEXT: [[X:%.*]] = and i32 [[P1:%.*]], 7
1517+
; CHECK-NEXT: [[Y:%.*]] = shl i32 [[P2:%.*]], 3
1518+
; CHECK-NEXT: [[M:%.*]] = mul i32 [[Y]], [[X]]
1519+
; CHECK-NEXT: [[R:%.*]] = or disjoint i32 [[M]], [[X]]
1520+
; CHECK-NEXT: ret i32 [[R]]
1521+
;
1522+
%x = and i32 %p1, 7
1523+
%y = shl i32 %p2, 3
1524+
%m = mul i32 %y, %x
1525+
%r = or i32 %m, %x
1526+
ret i32 %r
1527+
}
1528+
15141529
define i32 @mul_no_common_bits_disjoint(i32 %x, i32 %y) {
15151530
; CHECK-LABEL: @mul_no_common_bits_disjoint(
15161531
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[Y:%.*]], 1

0 commit comments

Comments
 (0)