1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
2 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefix=RV64 %s
5 define void @test(ptr nocapture noundef writeonly %array1, i32 noundef signext %a, i32 noundef signext %b) {
7 ; RV64: # %bb.0: # %entry
8 ; RV64-NEXT: addiw a3, a1, 5
9 ; RV64-NEXT: slli a4, a3, 2
10 ; RV64-NEXT: add a4, a0, a4
11 ; RV64-NEXT: sw a2, 0(a4)
12 ; RV64-NEXT: slli a1, a1, 2
13 ; RV64-NEXT: add a0, a1, a0
14 ; RV64-NEXT: sw a2, 24(a0)
15 ; RV64-NEXT: sw a3, 140(a0)
18 %add = add nsw i32 %a, 5
19 %idxprom = sext i32 %add to i64
20 %arrayidx = getelementptr inbounds i32, ptr %array1, i64 %idxprom
21 store i32 %b, ptr %arrayidx, align 4
22 %add3 = add nsw i32 %a, 6
23 %idxprom4 = sext i32 %add3 to i64
24 %arrayidx5 = getelementptr inbounds i32, ptr %array1, i64 %idxprom4
25 store i32 %b, ptr %arrayidx5, align 4
26 %add6 = add nsw i32 %a, 35
27 %idxprom7 = sext i32 %add6 to i64
28 %arrayidx8 = getelementptr inbounds i32, ptr %array1, i64 %idxprom7
29 store i32 %add, ptr %arrayidx8, align 4
33 ; test of jumpping, find add's operand has one more use can simplified
34 define void @test1(ptr nocapture noundef %array1, i32 noundef signext %a, i32 noundef signext %b, i32 noundef signext %x) {
36 ; RV64: # %bb.0: # %entry
37 ; RV64-NEXT: addiw a4, a1, 5
38 ; RV64-NEXT: slli a5, a4, 2
39 ; RV64-NEXT: add a5, a0, a5
40 ; RV64-NEXT: mv a6, a4
41 ; RV64-NEXT: bgtz a3, .LBB1_2
42 ; RV64-NEXT: # %bb.1: # %entry
43 ; RV64-NEXT: mv a6, a2
44 ; RV64-NEXT: .LBB1_2: # %entry
45 ; RV64-NEXT: sw a6, 0(a5)
46 ; RV64-NEXT: slli a1, a1, 2
47 ; RV64-NEXT: add a0, a1, a0
48 ; RV64-NEXT: sw a6, 24(a0)
49 ; RV64-NEXT: sw a4, 140(a0)
52 %add = add nsw i32 %a, 5
53 %cmp = icmp sgt i32 %x, 0
54 %idxprom = sext i32 %add to i64
55 %arrayidx = getelementptr inbounds i32, ptr %array1, i64 %idxprom
56 %add.b = select i1 %cmp, i32 %add, i32 %b
57 store i32 %add.b, ptr %arrayidx, align 4
58 %add5 = add nsw i32 %a, 6
59 %idxprom6 = sext i32 %add5 to i64
60 %arrayidx7 = getelementptr inbounds i32, ptr %array1, i64 %idxprom6
61 store i32 %add.b, ptr %arrayidx7, align 4
62 %add8 = add nsw i32 %a, 35
63 %idxprom9 = sext i32 %add8 to i64
64 %arrayidx10 = getelementptr inbounds i32, ptr %array1, i64 %idxprom9
65 store i32 %add, ptr %arrayidx10, align 4
69 define void @test2(ptr nocapture noundef writeonly %array1, i64 noundef %a, i64 noundef %b) local_unnamed_addr #0 {
71 ; RV64: # %bb.0: # %entry
72 ; RV64-NEXT: addi a3, a1, 5
73 ; RV64-NEXT: slli a4, a3, 3
74 ; RV64-NEXT: add a4, a0, a4
75 ; RV64-NEXT: sd a2, 0(a4)
76 ; RV64-NEXT: slli a1, a1, 3
77 ; RV64-NEXT: add a0, a1, a0
78 ; RV64-NEXT: sd a2, 48(a0)
79 ; RV64-NEXT: sd a3, 280(a0)
82 %add = add nsw i64 %a, 5
83 %arrayidx = getelementptr inbounds i64, ptr %array1, i64 %add
84 store i64 %b, ptr %arrayidx, align 8
85 %add2 = add nsw i64 %a, 6
86 %arrayidx3 = getelementptr inbounds i64, ptr %array1, i64 %add2
87 store i64 %b, ptr %arrayidx3, align 8
88 %add4 = add nsw i64 %a, 35
89 %arrayidx5 = getelementptr inbounds i64, ptr %array1, i64 %add4
90 store i64 %add, ptr %arrayidx5, align 8
94 define void @test3(ptr nocapture noundef %array1, i64 noundef %a, i64 noundef %b, i64 noundef %x) {
96 ; RV64: # %bb.0: # %entry
97 ; RV64-NEXT: addi a4, a1, 5
98 ; RV64-NEXT: mv a5, a4
99 ; RV64-NEXT: bgtz a3, .LBB3_2
100 ; RV64-NEXT: # %bb.1: # %entry
101 ; RV64-NEXT: mv a5, a2
102 ; RV64-NEXT: .LBB3_2: # %entry
103 ; RV64-NEXT: slli a2, a4, 3
104 ; RV64-NEXT: add a2, a0, a2
105 ; RV64-NEXT: sd a5, 0(a2)
106 ; RV64-NEXT: slli a1, a1, 3
107 ; RV64-NEXT: add a0, a1, a0
108 ; RV64-NEXT: sd a5, 48(a0)
109 ; RV64-NEXT: sd a4, 280(a0)
112 %add = add nsw i64 %a, 5
113 %cmp = icmp sgt i64 %x, 0
114 %spec.select = select i1 %cmp, i64 %add, i64 %b
115 %0 = getelementptr inbounds i64, ptr %array1, i64 %add
116 store i64 %spec.select, ptr %0, align 8
117 %add3 = add nsw i64 %a, 6
118 %arrayidx4 = getelementptr inbounds i64, ptr %array1, i64 %add3
119 store i64 %spec.select, ptr %arrayidx4, align 8
120 %add5 = add nsw i64 %a, 35
121 %arrayidx6 = getelementptr inbounds i64, ptr %array1, i64 %add5
122 store i64 %add, ptr %arrayidx6, align 8