[flang-commits] [flang] 2fb57d6 - [flang][NFC] Add tests for select constructs

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Sun Apr 3 06:19:08 PDT 2022


Author: Valentin Clement
Date: 2022-04-03T15:18:57+02:00
New Revision: 2fb57d628c6fb71fcd53364c451a018cb65fd2ba

URL: https://github.com/llvm/llvm-project/commit/2fb57d628c6fb71fcd53364c451a018cb65fd2ba
DIFF: https://github.com/llvm/llvm-project/commit/2fb57d628c6fb71fcd53364c451a018cb65fd2ba.diff

LOG: [flang][NFC] Add tests for select constructs

Add tests for fir.select_rank and
fir.select_case.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D122888

Co-authored-by: Jean Perier <jperier at nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz at nvidia.com>

Added: 
    flang/test/Fir/select.fir

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/flang/test/Fir/select.fir b/flang/test/Fir/select.fir
new file mode 100644
index 0000000000000..92883a2f6aaa8
--- /dev/null
+++ b/flang/test/Fir/select.fir
@@ -0,0 +1,68 @@
+// Test lowering FIR to LLVM IR of fir.select{|_rank|_case}
+
+// RUN: tco %s | FileCheck %s
+
+// CHECK-LABEL: @f
+func @f(%a : i32) -> i32 {
+   %1 = arith.constant 1 : i32
+   %2 = arith.constant 42 : i32
+// CHECK: switch i32 %{{.*}}, label %{{.*}} [
+// CHECK:   i32 1, label %{{.*}}
+// CHECK: ]
+   fir.select %a : i32 [1, ^bb2(%1:i32), unit, ^bb3(%2:i32)]
+^bb2(%3 : i32) :
+   return %3 : i32
+^bb3(%4 : i32) :
+   %5 = arith.addi %4, %4 : i32
+   // CHECK: ret i32
+   return %5 : i32 
+}
+
+// CHECK-LABEL: @g
+func @g(%a : i32) -> i32 {
+   %1 = arith.constant 1 : i32
+   %2 = arith.constant 42 : i32
+
+// CHECK: switch i32 %{{.*}}, label %{{.*}} [
+// CHECK:  i32 1, label %{{.*}}
+// CHECK:  i32 -1, label %{{.*}}
+// CHECK: ]
+   fir.select_rank %a : i32 [1, ^bb2(%1:i32), -1, ^bb4, unit, ^bb3(%2:i32)]
+^bb2(%3 : i32) :
+   return %3 : i32
+^bb3(%4 : i32) :
+   %5 = arith.addi %4, %4 : i32
+   return %5 : i32 
+^bb4:
+   // CHECK: ret i32
+   return %a : i32
+}
+
+// CHECK-LABEL: @h
+func @h(%a : i32) -> i32 {
+   %1 = arith.constant 1 : i32
+   %2 = arith.constant 42 : i32
+   %b1 = arith.constant 4 : i32
+   %b2 = arith.constant 14 : i32
+   %b3 = arith.constant 82 : i32
+   %b4 = arith.constant 96 : i32
+   // CHECK-DAG: icmp eq i32 %{{.*}}, 1
+   // CHECK-DAG: icmp sle i32 4, %{{.*}}
+   // CHECK-DAG: icmp sle i32 %{{.*}}, 14
+   // CHECK-DAG: icmp sle i32 82, %{{.*}}
+   // CHECK-DAG: icmp sle i32 %{{.*}}, 96
+   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)]
+^bb2(%3 : i32) :
+   return %3 : i32
+^bb3(%4 : i32) :
+   %5 = arith.addi %4, %4 : i32
+   cf.br ^bb2(%5 : i32) 
+^bb4:
+   return %a : i32
+^bb5:
+   return %1 : i32
+^bb6:
+   %x = arith.addi %b4, %b3 : i32
+   // CHECK: ret i32
+   return %x : i32
+}


        


More information about the flang-commits mailing list