• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1;; Test that (mul (add x, c1), c2) can be transformed to
2;; (add (mul x, c2), c1*c2) if profitable.
3
4; RUN: llc -mtriple=riscv32 -mattr=+m -verify-machineinstrs < %s \
5; RUN:   | FileCheck -check-prefix=RV32IM %s
6; RUN: llc -mtriple=riscv64 -mattr=+m -verify-machineinstrs < %s \
7; RUN:   | FileCheck -check-prefix=RV64IM %s
8
9define signext i32 @add_mul_trans_accept_1(i32 %x) {
10; RV32IM-LABEL: add_mul_trans_accept_1
11; RV32IM:       # %bb.0:
12; RV32IM-NEXT:    addi a1, zero, 11
13; RV32IM-NEXT:    mul a0, a0, a1
14; RV32IM-NEXT:    addi a0, a0, 407
15; RV32IM-NEXT:    ret
16;
17; RV64IM-LABEL: add_mul_trans_accept_1
18; RV64IM:       # %bb.0:
19; RV64IM-NEXT:    addi a1, zero, 11
20; RV64IM-NEXT:    mul a0, a0, a1
21; RV64IM-NEXT:    addiw a0, a0, 407
22; RV64IM-NEXT:    ret
23  %tmp0 = add i32 %x, 37
24  %tmp1 = mul i32 %tmp0, 11
25  ret i32 %tmp1
26}
27
28define signext i32 @add_mul_trans_accept_2(i32 %x) {
29; RV32IM-LABEL: add_mul_trans_accept_2
30; RV32IM:       # %bb.0:
31; RV32IM-NEXT:    addi a1, zero, 13
32; RV32IM-NEXT:    mul a0, a0, a1
33; RV32IM-NEXT:    lui a1, 28
34; RV32IM-NEXT:    addi a1, a1, 1701
35; RV32IM-NEXT:    add a0, a0, a1
36; RV32IM-NEXT:    ret
37;
38; RV64IM-LABEL: add_mul_trans_accept_2
39; RV64IM:       # %bb.0:
40; RV64IM-NEXT:    addi a1, zero, 13
41; RV64IM-NEXT:    mul a0, a0, a1
42; RV64IM-NEXT:    lui a1, 28
43; RV64IM-NEXT:    addiw a1, a1, 1701
44; RV64IM-NEXT:    addw a0, a0, a1
45; RV64IM-NEXT:    ret
46  %tmp0 = add i32 %x, 8953
47  %tmp1 = mul i32 %tmp0, 13
48  ret i32 %tmp1
49}
50
51define signext i32 @add_mul_trans_reject_1(i32 %x) {
52; RV32IM-LABEL: add_mul_trans_reject_1
53; RV32IM:       # %bb.0:
54; RV32IM-NEXT:    addi a1, zero, 19
55; RV32IM-NEXT:    mul a0, a0, a1
56; RV32IM-NEXT:    lui a1, 9
57; RV32IM-NEXT:    addi a1, a1, 585
58; RV32IM-NEXT:    add a0, a0, a1
59; RV32IM-NEXT:    ret
60;
61; RV64IM-LABEL: add_mul_trans_reject_1
62; RV64IM:       # %bb.0:
63; RV64IM-NEXT:    addi a1, zero, 19
64; RV64IM-NEXT:    mul a0, a0, a1
65; RV64IM-NEXT:    lui a1, 9
66; RV64IM-NEXT:    addiw a1, a1, 585
67; RV64IM-NEXT:    addw a0, a0, a1
68; RV64IM-NEXT:    ret
69  %tmp0 = add i32 %x, 1971
70  %tmp1 = mul i32 %tmp0, 19
71  ret i32 %tmp1
72}
73
74define signext i32 @add_mul_trans_reject_2(i32 %x) {
75; RV32IM:       # %bb.0:
76; RV32IM-NEXT:    lui a1, 792
77; RV32IM-NEXT:    addi a1, a1, -1709
78; RV32IM-NEXT:    mul a0, a0, a1
79; RV32IM-NEXT:    lui a1, 1014660
80; RV32IM-NEXT:    addi a1, a1, -1891
81; RV32IM-NEXT:    add a0, a0, a1
82; RV32IM-NEXT:    ret
83;
84; RV64IM:       # %bb.0:
85; RV64IM-NEXT:    lui a1, 792
86; RV64IM-NEXT:    addiw a1, a1, -1709
87; RV64IM-NEXT:    mul a0, a0, a1
88; RV64IM-NEXT:    lui a1, 1014660
89; RV64IM-NEXT:    addiw a1, a1, -1891
90; RV64IM-NEXT:    addw a0, a0, a1
91; RV64IM-NEXT:    ret
92  %tmp0 = add i32 %x, 1841231
93  %tmp1 = mul i32 %tmp0, 3242323
94  ret i32 %tmp1
95}
96