1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -O0 --mtriple=loongarch64 --verify-machineinstrs < %s | FileCheck %s
4 ;; This test case is reduced from pr17377.c of the GCC C Torture Suite using
7 @calls = external dso_local global i32, align 4
8 declare ptr @llvm.returnaddress(i32 immarg)
10 define dso_local ptr @f(i32 noundef signext %i) "frame-pointer"="all" {
12 ; CHECK: # %bb.0: # %entry
13 ; CHECK-NEXT: addi.d $sp, $sp, -48
14 ; CHECK-NEXT: .cfi_def_cfa_offset 48
15 ; CHECK-NEXT: st.d $ra, $sp, 40 # 8-byte Folded Spill
16 ; CHECK-NEXT: st.d $fp, $sp, 32 # 8-byte Folded Spill
17 ; CHECK-NEXT: .cfi_offset 1, -8
18 ; CHECK-NEXT: .cfi_offset 22, -16
19 ; CHECK-NEXT: addi.d $fp, $sp, 48
20 ; CHECK-NEXT: .cfi_def_cfa 22, 0
21 ; CHECK-NEXT: st.d $ra, $fp, -40 # 8-byte Folded Spill
22 ; CHECK-NEXT: move $a1, $a0
23 ; CHECK-NEXT: pcalau12i $a0, %pc_hi20(calls)
24 ; CHECK-NEXT: addi.d $a3, $a0, %pc_lo12(calls)
25 ; CHECK-NEXT: ld.w $a0, $a3, 0
26 ; CHECK-NEXT: addi.d $a2, $a0, 1
27 ; CHECK-NEXT: st.w $a2, $a3, 0
28 ; CHECK-NEXT: st.w $a1, $fp, -28
29 ; CHECK-NEXT: bnez $a0, .LBB0_2
30 ; CHECK-NEXT: b .LBB0_1
31 ; CHECK-NEXT: .LBB0_1: # %if.then
32 ; CHECK-NEXT: ld.d $a0, $fp, -40 # 8-byte Folded Reload
33 ; CHECK-NEXT: st.d $a0, $fp, -24
34 ; CHECK-NEXT: b .LBB0_7
35 ; CHECK-NEXT: .LBB0_2: # %if.end
36 ; CHECK-NEXT: ld.w $a0, $fp, -28
37 ; CHECK-NEXT: st.d $a0, $fp, -48 # 8-byte Folded Spill
38 ; CHECK-NEXT: beqz $a0, .LBB0_5
39 ; CHECK-NEXT: b .LBB0_3
40 ; CHECK-NEXT: .LBB0_3: # %if.end
41 ; CHECK-NEXT: ld.d $a0, $fp, -48 # 8-byte Folded Reload
42 ; CHECK-NEXT: ori $a1, $zero, 1
43 ; CHECK-NEXT: bne $a0, $a1, .LBB0_6
44 ; CHECK-NEXT: b .LBB0_4
45 ; CHECK-NEXT: .LBB0_4: # %sw.bb
46 ; CHECK-NEXT: pcalau12i $a0, %pc_hi20(f)
47 ; CHECK-NEXT: addi.d $a0, $a0, %pc_lo12(f)
48 ; CHECK-NEXT: st.d $a0, $fp, -24
49 ; CHECK-NEXT: b .LBB0_7
50 ; CHECK-NEXT: .LBB0_5: # %sw.bb1
51 ; CHECK-NEXT: ld.d $a0, $fp, -40 # 8-byte Folded Reload
52 ; CHECK-NEXT: st.d $a0, $fp, -24
53 ; CHECK-NEXT: b .LBB0_7
54 ; CHECK-NEXT: .LBB0_6: # %sw.epilog
55 ; CHECK-NEXT: move $a0, $zero
56 ; CHECK-NEXT: st.d $a0, $fp, -24
57 ; CHECK-NEXT: b .LBB0_7
58 ; CHECK-NEXT: .LBB0_7: # %return
59 ; CHECK-NEXT: ld.d $a0, $fp, -24
60 ; CHECK-NEXT: ld.d $fp, $sp, 32 # 8-byte Folded Reload
61 ; CHECK-NEXT: ld.d $ra, $sp, 40 # 8-byte Folded Reload
62 ; CHECK-NEXT: addi.d $sp, $sp, 48
65 %retval = alloca ptr, align 8
66 %i.addr = alloca i32, align 4
67 store i32 %i, ptr %i.addr, align 4
68 %0 = load i32, ptr @calls, align 4
69 %inc = add nsw i32 %0, 1
70 store i32 %inc, ptr @calls, align 4
71 %cmp = icmp eq i32 %0, 0
72 br i1 %cmp, label %if.then, label %if.end
75 %1 = call ptr @llvm.returnaddress(i32 0)
76 store ptr %1, ptr %retval, align 8
80 %2 = load i32, ptr %i.addr, align 4
81 switch i32 %2, label %sw.epilog [
87 store ptr @f, ptr %retval, align 8
91 %3 = call ptr @llvm.returnaddress(i32 0)
92 store ptr %3, ptr %retval, align 8
96 store ptr null, ptr %retval, align 8
100 %4 = load ptr, ptr %retval, align 8