|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 |
| 2 | +; RUN: llc -mtriple=riscv64 -mattr=+zicond < %s | FileCheck %s --check-prefixes=CHECK,CHEAP |
| 3 | +; RUN: llc -mtriple=riscv64 -mattr=+zicond,+predictable-select-expensive < %s | FileCheck %s --check-prefixes=CHECK,EXPENSIVE |
| 4 | + |
| 5 | +; Test has not predictable select, which should not be transformed to a branch |
| 6 | +define i32 @test1(i32 %a) { |
| 7 | +; CHECK-LABEL: test1: |
| 8 | +; CHECK: # %bb.0: # %entry |
| 9 | +; CHECK-NEXT: sext.w a1, a0 |
| 10 | +; CHECK-NEXT: slti a1, a1, 1 |
| 11 | +; CHECK-NEXT: addiw a0, a0, -1 |
| 12 | +; CHECK-NEXT: czero.nez a0, a0, a1 |
| 13 | +; CHECK-NEXT: ret |
| 14 | +entry: |
| 15 | + %cmp = icmp slt i32 %a, 1 |
| 16 | + %dec = sub i32 %a, 1 |
| 17 | + %res = select i1 %cmp, i32 0, i32 %dec, !prof !0 |
| 18 | + ret i32 %res |
| 19 | +} |
| 20 | + |
| 21 | +; Test has highly predictable select according to profile data, |
| 22 | +; which should be transformed to a branch on cores with enabled FeaturePredictableSelectIsExpensive |
| 23 | +define i32 @test2(i32 %a) { |
| 24 | +; CHEAP-LABEL: test2: |
| 25 | +; CHEAP: # %bb.0: # %entry |
| 26 | +; CHEAP-NEXT: sext.w a1, a0 |
| 27 | +; CHEAP-NEXT: slti a1, a1, 1 |
| 28 | +; CHEAP-NEXT: addiw a0, a0, -1 |
| 29 | +; CHEAP-NEXT: czero.nez a0, a0, a1 |
| 30 | +; CHEAP-NEXT: ret |
| 31 | +; |
| 32 | +; EXPENSIVE-LABEL: test2: |
| 33 | +; EXPENSIVE: # %bb.0: # %entry |
| 34 | +; EXPENSIVE-NEXT: sext.w a1, a0 |
| 35 | +; EXPENSIVE-NEXT: blez a1, .LBB1_2 |
| 36 | +; EXPENSIVE-NEXT: # %bb.1: # %select.false |
| 37 | +; EXPENSIVE-NEXT: addiw a0, a0, -1 |
| 38 | +; EXPENSIVE-NEXT: ret |
| 39 | +; EXPENSIVE-NEXT: .LBB1_2: |
| 40 | +; EXPENSIVE-NEXT: li a0, 0 |
| 41 | +; EXPENSIVE-NEXT: ret |
| 42 | +entry: |
| 43 | + %cmp = icmp slt i32 %a, 1 |
| 44 | + %dec = sub i32 %a, 1 |
| 45 | + %res = select i1 %cmp, i32 0, i32 %dec, !prof !1 |
| 46 | + ret i32 %res |
| 47 | +} |
| 48 | + |
| 49 | +!0 = !{!"branch_weights", i32 1, i32 1} |
| 50 | +!1 = !{!"branch_weights", i32 1, i32 1000} |
0 commit comments