Valentin Clement | 2fb57d6 | 2022-04-03 13:17:21 | [diff] [blame] | 1 | // Test lowering FIR to LLVM IR of fir.select{|_rank|_case} |
| 2 | |
| 3 | // RUN: tco %s | FileCheck %s |
Andrzej Warzynski | cc3c6b6 | 2022-06-01 16:00:31 | [diff] [blame] | 4 | // RUN: %flang_fc1 -emit-llvm %s -o - | FileCheck %s |
Valentin Clement | 2fb57d6 | 2022-04-03 13:17:21 | [diff] [blame] | 5 | |
| 6 | // CHECK-LABEL: @f |
River Riddle | a8308020 | 2022-04-21 04:39:22 | [diff] [blame] | 7 | func.func @f(%a : i32) -> i32 { |
Valentin Clement | 2fb57d6 | 2022-04-03 13:17:21 | [diff] [blame] | 8 | %1 = arith.constant 1 : i32 |
| 9 | %2 = arith.constant 42 : i32 |
| 10 | // CHECK: switch i32 %{{.*}}, label %{{.*}} [ |
| 11 | // CHECK: i32 1, label %{{.*}} |
| 12 | // CHECK: ] |
| 13 | fir.select %a : i32 [1, ^bb2(%1:i32), unit, ^bb3(%2:i32)] |
| 14 | ^bb2(%3 : i32) : |
| 15 | return %3 : i32 |
| 16 | ^bb3(%4 : i32) : |
| 17 | %5 = arith.addi %4, %4 : i32 |
| 18 | // CHECK: ret i32 |
| 19 | return %5 : i32 |
| 20 | } |
| 21 | |
| 22 | // CHECK-LABEL: @g |
River Riddle | a8308020 | 2022-04-21 04:39:22 | [diff] [blame] | 23 | func.func @g(%a : i32) -> i32 { |
Valentin Clement | 2fb57d6 | 2022-04-03 13:17:21 | [diff] [blame] | 24 | %1 = arith.constant 1 : i32 |
| 25 | %2 = arith.constant 42 : i32 |
| 26 | |
| 27 | // CHECK: switch i32 %{{.*}}, label %{{.*}} [ |
| 28 | // CHECK: i32 1, label %{{.*}} |
| 29 | // CHECK: i32 -1, label %{{.*}} |
| 30 | // CHECK: ] |
| 31 | fir.select_rank %a : i32 [1, ^bb2(%1:i32), -1, ^bb4, unit, ^bb3(%2:i32)] |
| 32 | ^bb2(%3 : i32) : |
| 33 | return %3 : i32 |
| 34 | ^bb3(%4 : i32) : |
| 35 | %5 = arith.addi %4, %4 : i32 |
| 36 | return %5 : i32 |
| 37 | ^bb4: |
| 38 | // CHECK: ret i32 |
| 39 | return %a : i32 |
| 40 | } |
| 41 | |
| 42 | // CHECK-LABEL: @h |
River Riddle | a8308020 | 2022-04-21 04:39:22 | [diff] [blame] | 43 | func.func @h(%a : i32) -> i32 { |
Valentin Clement | 2fb57d6 | 2022-04-03 13:17:21 | [diff] [blame] | 44 | %1 = arith.constant 1 : i32 |
| 45 | %2 = arith.constant 42 : i32 |
| 46 | %b1 = arith.constant 4 : i32 |
| 47 | %b2 = arith.constant 14 : i32 |
| 48 | %b3 = arith.constant 82 : i32 |
| 49 | %b4 = arith.constant 96 : i32 |
| 50 | // CHECK-DAG: icmp eq i32 %{{.*}}, 1 |
| 51 | // CHECK-DAG: icmp sle i32 4, %{{.*}} |
| 52 | // CHECK-DAG: icmp sle i32 %{{.*}}, 14 |
| 53 | // CHECK-DAG: icmp sle i32 82, %{{.*}} |
| 54 | // CHECK-DAG: icmp sle i32 %{{.*}}, 96 |
| 55 | fir.select_case %a : i32 [#fir.point, %1, ^bb2(%1:i32), #fir.lower, %b1, ^bb4, #fir.upper, %b2, ^bb6, #fir.interval, %b3, %b4, ^bb5, unit, ^bb3(%2:i32)] |
| 56 | ^bb2(%3 : i32) : |
| 57 | return %3 : i32 |
| 58 | ^bb3(%4 : i32) : |
| 59 | %5 = arith.addi %4, %4 : i32 |
| 60 | cf.br ^bb2(%5 : i32) |
| 61 | ^bb4: |
| 62 | return %a : i32 |
| 63 | ^bb5: |
| 64 | return %1 : i32 |
| 65 | ^bb6: |
| 66 | %x = arith.addi %b4, %b3 : i32 |
| 67 | // CHECK: ret i32 |
| 68 | return %x : i32 |
| 69 | } |