Alex Bradbury | e027c93 | 2018-01-10 20:47:00 +0000 | [diff] [blame] | 1 | ; 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 | |
| 8 | declare void @test_true() |
| 9 | declare 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 | |
| 15 | define 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 Bradbury | e027c93 | 2018-01-10 20:47:00 +0000 | [diff] [blame] | 20 | ; RV32I-NEXT: addi a1, zero, 42 |
| 21 | ; RV32I-NEXT: bne a0, a1, .LBB0_3 |
| 22 | ; RV32I-NEXT: # %bb.1: # %true |
Shiva Chen | d58bd8d | 2018-04-25 14:19:12 +0000 | [diff] [blame] | 23 | ; RV32I-NEXT: call test_true |
Alex Bradbury | e027c93 | 2018-01-10 20:47:00 +0000 | [diff] [blame] | 24 | ; RV32I-NEXT: .LBB0_2: # %true |
Alex Bradbury | e027c93 | 2018-01-10 20:47:00 +0000 | [diff] [blame] | 25 | ; RV32I-NEXT: lw ra, 12(sp) |
| 26 | ; RV32I-NEXT: addi sp, sp, 16 |
| 27 | ; RV32I-NEXT: ret |
| 28 | ; RV32I-NEXT: .LBB0_3: # %false |
Shiva Chen | d58bd8d | 2018-04-25 14:19:12 +0000 | [diff] [blame] | 29 | ; RV32I-NEXT: call test_false |
Alex Bradbury | e027c93 | 2018-01-10 20:47:00 +0000 | [diff] [blame] | 30 | ; RV32I-NEXT: j .LBB0_2 |
| 31 | %tst = icmp eq i32 %in, 42 |
| 32 | br i1 %tst, label %true, label %false, !prof !0 |
| 33 | |
| 34 | ; Expected layout order is: Entry, TrueBlock, FalseBlock |
| 35 | ; Entry->TrueBlock is the common path, which should be taken whenever the |
| 36 | ; conditional branch is false. |
| 37 | |
| 38 | true: |
| 39 | call void @test_true() |
| 40 | ret void |
| 41 | |
| 42 | false: |
| 43 | call void @test_false() |
| 44 | ret void |
| 45 | } |
| 46 | |
| 47 | define void @test_bcc_fallthrough_nottaken(i32 %in) nounwind { |
| 48 | ; RV32I-LABEL: test_bcc_fallthrough_nottaken: |
| 49 | ; RV32I: # %bb.0: |
| 50 | ; RV32I-NEXT: addi sp, sp, -16 |
| 51 | ; RV32I-NEXT: sw ra, 12(sp) |
Alex Bradbury | e027c93 | 2018-01-10 20:47:00 +0000 | [diff] [blame] | 52 | ; RV32I-NEXT: addi a1, zero, 42 |
Alex Bradbury | 315cd3a | 2018-01-10 21:05:07 +0000 | [diff] [blame] | 53 | ; RV32I-NEXT: beq a0, a1, .LBB1_3 |
| 54 | ; RV32I-NEXT: # %bb.1: # %false |
Shiva Chen | d58bd8d | 2018-04-25 14:19:12 +0000 | [diff] [blame] | 55 | ; RV32I-NEXT: call test_false |
Alex Bradbury | e027c93 | 2018-01-10 20:47:00 +0000 | [diff] [blame] | 56 | ; RV32I-NEXT: .LBB1_2: # %true |
Alex Bradbury | e027c93 | 2018-01-10 20:47:00 +0000 | [diff] [blame] | 57 | ; RV32I-NEXT: lw ra, 12(sp) |
| 58 | ; RV32I-NEXT: addi sp, sp, 16 |
| 59 | ; RV32I-NEXT: ret |
Alex Bradbury | 315cd3a | 2018-01-10 21:05:07 +0000 | [diff] [blame] | 60 | ; RV32I-NEXT: .LBB1_3: # %true |
Shiva Chen | d58bd8d | 2018-04-25 14:19:12 +0000 | [diff] [blame] | 61 | ; RV32I-NEXT: call test_true |
Alex Bradbury | e027c93 | 2018-01-10 20:47:00 +0000 | [diff] [blame] | 62 | ; RV32I-NEXT: j .LBB1_2 |
| 63 | %tst = icmp eq i32 %in, 42 |
| 64 | br i1 %tst, label %true, label %false, !prof !1 |
| 65 | |
| 66 | ; Expected layout order is: Entry, FalseBlock, TrueBlock |
| 67 | ; Entry->FalseBlock is the common path, which should be taken whenever the |
| 68 | ; conditional branch is false |
| 69 | |
| 70 | true: |
| 71 | call void @test_true() |
| 72 | ret void |
| 73 | |
| 74 | false: |
| 75 | call void @test_false() |
| 76 | ret void |
| 77 | } |
| 78 | |
| 79 | ; TODO: how can we expand the coverage of the branch analysis functions? |