1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -mattr=+m,+v < %s | FileCheck %s
3 ; RUN: llc -mtriple=riscv64 -mattr=+m,+v < %s | FileCheck %s
5 ; fold (and (or x, C), D) -> D if (C & D) == D
7 define <vscale x 4 x i32> @and_or_nxv4i32(<vscale x 4 x i32> %A) {
8 ; CHECK-LABEL: and_or_nxv4i32:
10 ; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, ma
11 ; CHECK-NEXT: vmv.v.i v8, 8
13 %ins1 = insertelement <vscale x 4 x i32> poison, i32 255, i32 0
14 %splat1 = shufflevector <vscale x 4 x i32> %ins1, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
15 %ins2 = insertelement <vscale x 4 x i32> poison, i32 8, i32 0
16 %splat2 = shufflevector <vscale x 4 x i32> %ins2, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
17 %v1 = or <vscale x 4 x i32> %A, %splat1
18 %v2 = and <vscale x 4 x i32> %v1, %splat2
19 ret <vscale x 4 x i32> %v2
22 ; (or (and X, c1), c2) -> (and (or X, c2), c1|c2) iff (c1 & c2) != 0
24 define <vscale x 2 x i64> @or_and_nxv2i64(<vscale x 2 x i64> %a0) {
25 ; CHECK-LABEL: or_and_nxv2i64:
27 ; CHECK-NEXT: vsetvli a0, zero, e64, m2, ta, ma
28 ; CHECK-NEXT: vor.vi v8, v8, 3
29 ; CHECK-NEXT: vand.vi v8, v8, 7
31 %ins1 = insertelement <vscale x 2 x i64> poison, i64 7, i32 0
32 %splat1 = shufflevector <vscale x 2 x i64> %ins1, <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
33 %ins2 = insertelement <vscale x 2 x i64> poison, i64 3, i32 0
34 %splat2 = shufflevector <vscale x 2 x i64> %ins2, <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
35 %v1 = and <vscale x 2 x i64> %a0, %splat1
36 %v2 = or <vscale x 2 x i64> %v1, %splat2
37 ret <vscale x 2 x i64> %v2
40 ; If all masked bits are going to be set, that's a constant fold.
42 define <vscale x 2 x i64> @or_and_nxv2i64_fold(<vscale x 2 x i64> %a0) {
43 ; CHECK-LABEL: or_and_nxv2i64_fold:
45 ; CHECK-NEXT: vsetvli a0, zero, e64, m2, ta, ma
46 ; CHECK-NEXT: vmv.v.i v8, 3
48 %ins1 = insertelement <vscale x 2 x i64> poison, i64 1, i32 0
49 %splat1 = shufflevector <vscale x 2 x i64> %ins1, <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
50 %ins2 = insertelement <vscale x 2 x i64> poison, i64 3, i32 0
51 %splat2 = shufflevector <vscale x 2 x i64> %ins2, <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
52 %v1 = and <vscale x 2 x i64> %a0, %splat1
53 %v2 = or <vscale x 2 x i64> %v1, %splat2
54 ret <vscale x 2 x i64> %v2
57 ; fold (shl (shl x, c1), c2) -> (shl x, (add c1, c2))
59 define <vscale x 4 x i32> @combine_vec_shl_shl(<vscale x 4 x i32> %x) {
60 ; CHECK-LABEL: combine_vec_shl_shl:
62 ; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, ma
63 ; CHECK-NEXT: vsll.vi v8, v8, 6
65 %ins1 = insertelement <vscale x 4 x i32> poison, i32 2, i32 0
66 %splat1 = shufflevector <vscale x 4 x i32> %ins1, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
67 %ins2 = insertelement <vscale x 4 x i32> poison, i32 4, i32 0
68 %splat2 = shufflevector <vscale x 4 x i32> %ins2, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
69 %v1 = shl <vscale x 4 x i32> %x, %splat1
70 %v2 = shl <vscale x 4 x i32> %v1, %splat2
71 ret <vscale x 4 x i32> %v2
74 ; fold (sra (sra x, c1), c2) -> (sra x, (add c1, c2))
76 define <vscale x 2 x i32> @combine_vec_ashr_ashr(<vscale x 2 x i32> %x) {
77 ; CHECK-LABEL: combine_vec_ashr_ashr:
79 ; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, ma
80 ; CHECK-NEXT: vsra.vi v8, v8, 6
82 %ins1 = insertelement <vscale x 2 x i32> poison, i32 2, i32 0
83 %splat1 = shufflevector <vscale x 2 x i32> %ins1, <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer
84 %ins2 = insertelement <vscale x 2 x i32> poison, i32 4, i32 0
85 %splat2 = shufflevector <vscale x 2 x i32> %ins2, <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer
86 %v1 = ashr <vscale x 2 x i32> %x, %splat1
87 %v2 = ashr <vscale x 2 x i32> %v1, %splat2
88 ret <vscale x 2 x i32> %v2
91 ; fold (srl (srl x, c1), c2) -> (srl x, (add c1, c2))
93 define <vscale x 8 x i16> @combine_vec_lshr_lshr(<vscale x 8 x i16> %x) {
94 ; CHECK-LABEL: combine_vec_lshr_lshr:
96 ; CHECK-NEXT: vsetvli a0, zero, e16, m2, ta, ma
97 ; CHECK-NEXT: vsrl.vi v8, v8, 8
99 %ins1 = insertelement <vscale x 8 x i16> poison, i16 2, i32 0
100 %splat1 = shufflevector <vscale x 8 x i16> %ins1, <vscale x 8 x i16> poison, <vscale x 8 x i32> zeroinitializer
101 %ins2 = insertelement <vscale x 8 x i16> poison, i16 4, i32 0
102 %splat2 = shufflevector <vscale x 8 x i16> %ins2, <vscale x 8 x i16> poison, <vscale x 8 x i32> zeroinitializer
103 %v1 = lshr <vscale x 8 x i16> %x, %splat2
104 %v2 = lshr <vscale x 8 x i16> %v1, %splat2
105 ret <vscale x 8 x i16> %v2
108 ; fold (fmul x, 1.0) -> x
109 define <vscale x 2 x float> @combine_fmul_one(<vscale x 2 x float> %x) {
110 ; CHECK-LABEL: combine_fmul_one:
113 %ins = insertelement <vscale x 2 x float> poison, float 1.0, i32 0
114 %splat = shufflevector <vscale x 2 x float> %ins, <vscale x 2 x float> poison, <vscale x 2 x i32> zeroinitializer
115 %v = fmul <vscale x 2 x float> %x, %splat
116 ret <vscale x 2 x float> %v
119 ; fold (fmul 1.0, x) -> x
120 define <vscale x 2 x float> @combine_fmul_one_commuted(<vscale x 2 x float> %x) {
121 ; CHECK-LABEL: combine_fmul_one_commuted:
124 %ins = insertelement <vscale x 2 x float> poison, float 1.0, i32 0
125 %splat = shufflevector <vscale x 2 x float> %ins, <vscale x 2 x float> poison, <vscale x 2 x i32> zeroinitializer
126 %v = fmul <vscale x 2 x float> %splat, %x
127 ret <vscale x 2 x float> %v