blob: bf34a0d9f9f4c3df56b6a5cce96b5e8713f64a01 [file] [log] [blame]
Alex Bradburye027c932018-01-10 20:47:00 +00001; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3; RUN: | FileCheck -check-prefix=RV32I %s
4
5; This test checks that LLVM can do basic stripping and reapplying of branches
6; to basic blocks.
7
8declare void @test_true()
9declare void @test_false()
10
11; !0 corresponds to a branch being taken, !1 to not being takne.
12!0 = !{!"branch_weights", i32 64, i32 4}
13!1 = !{!"branch_weights", i32 4, i32 64}
14
15define void @test_bcc_fallthrough_taken(i32 %in) nounwind {
16; RV32I-LABEL: test_bcc_fallthrough_taken:
17; RV32I: # %bb.0:
18; RV32I-NEXT: addi sp, sp, -16
19; RV32I-NEXT: sw ra, 12(sp)
Alex Bradburye027c932018-01-10 20:47:00 +000020; RV32I-NEXT: addi a1, zero, 42
21; RV32I-NEXT: bne a0, a1, .LBB0_3
22; RV32I-NEXT: # %bb.1: # %true
23; RV32I-NEXT: lui a0, %hi(test_true)
24; RV32I-NEXT: addi a0, a0, %lo(test_true)
25; RV32I-NEXT: .LBB0_2: # %true
26; RV32I-NEXT: jalr a0
Alex Bradburye027c932018-01-10 20:47:00 +000027; RV32I-NEXT: lw ra, 12(sp)
28; RV32I-NEXT: addi sp, sp, 16
29; RV32I-NEXT: ret
30; RV32I-NEXT: .LBB0_3: # %false
31; RV32I-NEXT: lui a0, %hi(test_false)
32; RV32I-NEXT: addi a0, a0, %lo(test_false)
33; RV32I-NEXT: j .LBB0_2
34 %tst = icmp eq i32 %in, 42
35 br i1 %tst, label %true, label %false, !prof !0
36
37; Expected layout order is: Entry, TrueBlock, FalseBlock
38; Entry->TrueBlock is the common path, which should be taken whenever the
39; conditional branch is false.
40
41true:
42 call void @test_true()
43 ret void
44
45false:
46 call void @test_false()
47 ret void
48}
49
50define void @test_bcc_fallthrough_nottaken(i32 %in) nounwind {
51; RV32I-LABEL: test_bcc_fallthrough_nottaken:
52; RV32I: # %bb.0:
53; RV32I-NEXT: addi sp, sp, -16
54; RV32I-NEXT: sw ra, 12(sp)
Alex Bradburye027c932018-01-10 20:47:00 +000055; RV32I-NEXT: addi a1, zero, 42
Alex Bradbury315cd3a2018-01-10 21:05:07 +000056; RV32I-NEXT: beq a0, a1, .LBB1_3
57; RV32I-NEXT: # %bb.1: # %false
Alex Bradburye027c932018-01-10 20:47:00 +000058; RV32I-NEXT: lui a0, %hi(test_false)
59; RV32I-NEXT: addi a0, a0, %lo(test_false)
60; RV32I-NEXT: .LBB1_2: # %true
61; RV32I-NEXT: jalr a0
Alex Bradburye027c932018-01-10 20:47:00 +000062; RV32I-NEXT: lw ra, 12(sp)
63; RV32I-NEXT: addi sp, sp, 16
64; RV32I-NEXT: ret
Alex Bradbury315cd3a2018-01-10 21:05:07 +000065; RV32I-NEXT: .LBB1_3: # %true
Alex Bradburye027c932018-01-10 20:47:00 +000066; RV32I-NEXT: lui a0, %hi(test_true)
67; RV32I-NEXT: addi a0, a0, %lo(test_true)
68; RV32I-NEXT: j .LBB1_2
69 %tst = icmp eq i32 %in, 42
70 br i1 %tst, label %true, label %false, !prof !1
71
72; Expected layout order is: Entry, FalseBlock, TrueBlock
73; Entry->FalseBlock is the common path, which should be taken whenever the
74; conditional branch is false
75
76true:
77 call void @test_true()
78 ret void
79
80false:
81 call void @test_false()
82 ret void
83}
84
85; TODO: how can we expand the coverage of the branch analysis functions?