[flang-commits] [flang] 602dd6b - [flang][NFC] Add tests for fir.is_present
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Sun Apr 3 06:22:42 PDT 2022
Author: Valentin Clement
Date: 2022-04-03T15:22:33+02:00
New Revision: 602dd6bd32ab6f4ae8acebff0eacef8e2261fe49
URL: https://github.com/llvm/llvm-project/commit/602dd6bd32ab6f4ae8acebff0eacef8e2261fe49
DIFF: https://github.com/llvm/llvm-project/commit/602dd6bd32ab6f4ae8acebff0eacef8e2261fe49.diff
LOG: [flang][NFC] Add tests for fir.is_present
This patch adds tests for the `fir.is_present`
translation.
This patch is part of the upstreaming effort from fir-dev branch.
Reviewed By: jeanPerier
Differential Revision: https://reviews.llvm.org/D122813
Co-authored-by: Jean Perier <jperier at nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz at nvidia.com>
Added:
flang/test/Fir/optional.fir
Modified:
Removed:
################################################################################
diff --git a/flang/test/Fir/optional.fir b/flang/test/Fir/optional.fir
new file mode 100644
index 0000000000000..95d3036fe7d27
--- /dev/null
+++ b/flang/test/Fir/optional.fir
@@ -0,0 +1,52 @@
+// RUN: tco %s | FileCheck %s
+
+// Test fir.is_present and fir.absent codegen
+
+// CHECK-LABEL: @foo1
+func @foo1(%arg0: !fir.box<!fir.array<?xf32>>) -> i1 {
+ // CHECK: %[[ptr:.*]] = ptrtoint { float*, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }* %{{.*}} to i64
+ // CHECK: icmp ne i64 %[[ptr]], 0
+ %0 = fir.is_present %arg0 : (!fir.box<!fir.array<?xf32>>) -> i1
+ return %0 : i1
+}
+
+// CHECK-LABEL: @bar1
+func @bar1() -> i1 {
+ %0 = fir.absent !fir.box<!fir.array<?xf32>>
+ // CHECK: call i1 @foo1({ float*, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }* null)
+ %1 = fir.call @foo1(%0) : (!fir.box<!fir.array<?xf32>>) -> i1
+ return %1 : i1
+}
+
+// CHECK-LABEL: @foo2
+func @foo2(%arg0: !fir.ref<i64>) -> i1 {
+ // CHECK: %[[ptr:.*]] = ptrtoint i64* %{{.*}} to i64
+ // CHECK: icmp ne i64 %[[ptr]], 0
+ %0 = fir.is_present %arg0 : (!fir.ref<i64>) -> i1
+ return %0 : i1
+}
+
+// CHECK-LABEL: @bar2
+func @bar2() -> i1 {
+ %0 = fir.absent !fir.ref<i64>
+ // CHECK: call i1 @foo2(i64* null)
+ %1 = fir.call @foo2(%0) : (!fir.ref<i64>) -> i1
+ return %1 : i1
+}
+
+// CHECK-LABEL: @foo3
+func @foo3(%arg0: !fir.boxchar<1>) -> i1 {
+ // CHECK: %[[extract:.*]] = extractvalue { i8*, i64 } %{{.*}}, 0
+ // CHECK: %[[ptr:.*]] = ptrtoint i8* %[[extract]] to i64
+ // CHECK: icmp ne i64 %[[ptr]], 0
+ %0 = fir.is_present %arg0 : (!fir.boxchar<1>) -> i1
+ return %0 : i1
+}
+
+// CHECK-LABEL: @bar3
+func @bar3() -> i1 {
+ %0 = fir.absent !fir.boxchar<1>
+ // CHECK: call i1 @foo3(i8* null, i64 undef)
+ %1 = fir.call @foo3(%0) : (!fir.boxchar<1>) -> i1
+ return %1 : i1
+}
More information about the flang-commits
mailing list