1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s | FileCheck %s
3 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s | FileCheck %s
5 @x = global [6 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5], align 4
6 @check = global [6 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5], align 4
8 ; This test case checks whether the base address of an array is repeatedly
9 ; rematerialised within a unrolled loop.
10 define signext i32 @unroll_loop_cse() {
11 ; CHECK-LABEL: unroll_loop_cse:
13 ; CHECK-NEXT: lui a1, %hi(x)
14 ; CHECK-NEXT: lw a3, %lo(x)(a1)
15 ; CHECK-NEXT: lui a2, %hi(check)
16 ; CHECK-NEXT: lw a4, %lo(check)(a2)
17 ; CHECK-NEXT: li a0, 1
18 ; CHECK-NEXT: bne a3, a4, .LBB0_6
19 ; CHECK-NEXT: # %bb.1:
20 ; CHECK-NEXT: addi a1, a1, %lo(x)
21 ; CHECK-NEXT: lw a1, 4(a1)
22 ; CHECK-NEXT: addi a2, a2, %lo(check)
23 ; CHECK-NEXT: lw a2, 4(a2)
24 ; CHECK-NEXT: bne a1, a2, .LBB0_6
25 ; CHECK-NEXT: # %bb.2:
26 ; CHECK-NEXT: lui a1, %hi(x)
27 ; CHECK-NEXT: addi a1, a1, %lo(x)
28 ; CHECK-NEXT: lw a3, 8(a1)
29 ; CHECK-NEXT: lui a2, %hi(check)
30 ; CHECK-NEXT: addi a2, a2, %lo(check)
31 ; CHECK-NEXT: lw a4, 8(a2)
32 ; CHECK-NEXT: bne a3, a4, .LBB0_6
33 ; CHECK-NEXT: # %bb.3:
34 ; CHECK-NEXT: lw a1, 12(a1)
35 ; CHECK-NEXT: lw a2, 12(a2)
36 ; CHECK-NEXT: bne a1, a2, .LBB0_6
37 ; CHECK-NEXT: # %bb.4:
38 ; CHECK-NEXT: lui a1, %hi(x)
39 ; CHECK-NEXT: addi a1, a1, %lo(x)
40 ; CHECK-NEXT: lw a3, 16(a1)
41 ; CHECK-NEXT: lui a2, %hi(check)
42 ; CHECK-NEXT: addi a2, a2, %lo(check)
43 ; CHECK-NEXT: lw a4, 16(a2)
44 ; CHECK-NEXT: bne a3, a4, .LBB0_6
45 ; CHECK-NEXT: # %bb.5:
46 ; CHECK-NEXT: lw a0, 20(a1)
47 ; CHECK-NEXT: lw a1, 20(a2)
48 ; CHECK-NEXT: xor a0, a0, a1
49 ; CHECK-NEXT: snez a0, a0
50 ; CHECK-NEXT: .LBB0_6:
52 %1 = load i32, ptr @x, align 4
53 %2 = load i32, ptr @check, align 4
54 %3 = icmp eq i32 %1, %2
55 br i1 %3, label %4, label %25
58 %5 = load i32, ptr getelementptr inbounds ([6 x i32], ptr @x, i64 0, i64 1), align 4
59 %6 = load i32, ptr getelementptr inbounds ([6 x i32], ptr @check, i64 0, i64 1), align 4
60 %7 = icmp eq i32 %5, %6
61 br i1 %7, label %8, label %25
64 %9 = load i32, ptr getelementptr inbounds ([6 x i32], ptr @x, i64 0, i64 2), align 4
65 %10 = load i32, ptr getelementptr inbounds ([6 x i32], ptr @check, i64 0, i64 2), align 4
66 %11 = icmp eq i32 %9, %10
67 br i1 %11, label %12, label %25
70 %13 = load i32, ptr getelementptr inbounds ([6 x i32], ptr @x, i64 0, i64 3), align 4
71 %14 = load i32, ptr getelementptr inbounds ([6 x i32], ptr @check, i64 0, i64 3), align 4
72 %15 = icmp eq i32 %13, %14
73 br i1 %15, label %16, label %25
76 %17 = load i32, ptr getelementptr inbounds ([6 x i32], ptr @x, i64 0, i64 4), align 4
77 %18 = load i32, ptr getelementptr inbounds ([6 x i32], ptr @check, i64 0, i64 4), align 4
78 %19 = icmp eq i32 %17, %18
79 br i1 %19, label %20, label %25
82 %21 = load i32, ptr getelementptr inbounds ([6 x i32], ptr @x, i64 0, i64 5), align 4
83 %22 = load i32, ptr getelementptr inbounds ([6 x i32], ptr @check, i64 0, i64 5), align 4
84 %23 = icmp ne i32 %21, %22
85 %24 = zext i1 %23 to i32
89 %26 = phi i32 [ 1, %0 ], [ 1, %4 ], [ 1, %8 ], [ 1, %12 ], [ 1, %16 ], [ %24, %20 ]