1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -O3 < %s -mtriple=riscv32 | FileCheck %s
4 ; These tests demonstrate optimizations involving copies from VLENB.
6 define void @unused_copy_is_dead() {
7 ; CHECK-LABEL: unused_copy_is_dead:
8 ; CHECK: # %bb.0: # %entry
11 call i32 @llvm.read_register.i32(metadata !0)
15 define i32 @simple_cse() {
16 ; CHECK-LABEL: simple_cse:
17 ; CHECK: # %bb.0: # %entry
18 ; CHECK-NEXT: csrr a0, vlenb
19 ; CHECK-NEXT: sub a0, a0, a0
22 %v1 = call i32 @llvm.read_register.i32(metadata !0)
23 %v2 = call i32 @llvm.read_register.i32(metadata !0)
24 %sub = sub i32 %v1, %v2
28 define i32 @sink_to_use_branch(i1 %c) {
29 ; CHECK-LABEL: sink_to_use_branch:
30 ; CHECK: # %bb.0: # %entry
31 ; CHECK-NEXT: andi a0, a0, 1
32 ; CHECK-NEXT: beqz a0, .LBB2_2
33 ; CHECK-NEXT: # %bb.1: # %used
34 ; CHECK-NEXT: csrr a0, vlenb
35 ; CHECK-NEXT: .LBB2_2: # %unused
38 %v1 = call i32 @llvm.read_register.i32(metadata !0)
39 br i1 %c, label %used, label %unused
46 define i32 @sink_to_use_call() {
47 ; CHECK-LABEL: sink_to_use_call:
48 ; CHECK: # %bb.0: # %entry
49 ; CHECK-NEXT: addi sp, sp, -16
50 ; CHECK-NEXT: .cfi_def_cfa_offset 16
51 ; CHECK-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
52 ; CHECK-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
53 ; CHECK-NEXT: .cfi_offset ra, -4
54 ; CHECK-NEXT: .cfi_offset s0, -8
55 ; CHECK-NEXT: csrr s0, vlenb
56 ; CHECK-NEXT: call unknown
57 ; CHECK-NEXT: mv a0, s0
58 ; CHECK-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
59 ; CHECK-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
60 ; CHECK-NEXT: addi sp, sp, 16
63 %v1 = call i32 @llvm.read_register.i32(metadata !0)
64 call void @unknown() ; maythrow
68 define void @machine_licm() {
69 ; CHECK-LABEL: machine_licm:
70 ; CHECK: # %bb.0: # %entry
71 ; CHECK-NEXT: addi sp, sp, -16
72 ; CHECK-NEXT: .cfi_def_cfa_offset 16
73 ; CHECK-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
74 ; CHECK-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
75 ; CHECK-NEXT: .cfi_offset ra, -4
76 ; CHECK-NEXT: .cfi_offset s0, -8
77 ; CHECK-NEXT: csrr s0, vlenb
78 ; CHECK-NEXT: .LBB4_1: # %loop
79 ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
80 ; CHECK-NEXT: mv a0, s0
81 ; CHECK-NEXT: call use
82 ; CHECK-NEXT: j .LBB4_1
87 %v1 = call i32 @llvm.read_register.i32(metadata !0)
88 call void @use(i32 %v1)
93 declare i32 @llvm.read_register.i32(metadata) nounwind
94 declare void @unknown()
95 declare void @use(i32)