summaryrefslogtreecommitdiffstats
path: root/clang/test/Frontend/fixed_point_to_bool.c
diff options
context:
space:
mode:
authorLeonard Chan <leonardchan@google.com>2018-10-23 17:55:35 +0000
committerLeonard Chan <leonardchan@google.com>2018-10-23 17:55:35 +0000
commitb4ba467da89353fda84a08175971859b1e52fde4 (patch)
tree5717ccd5f1108933d71925a52a4c7345119b6d10 /clang/test/Frontend/fixed_point_to_bool.c
parent29d8639732bc367aab862529779c70e43e463d0c (diff)
downloadbcm5719-llvm-b4ba467da89353fda84a08175971859b1e52fde4.tar.gz
bcm5719-llvm-b4ba467da89353fda84a08175971859b1e52fde4.zip
[Fixed Point Arithmetic] Fixed Point to Boolean Cast
This patch is a part of https://reviews.llvm.org/D48456 in an attempt to split the casting logic up into smaller patches. This contains the code for casting from fixed point types to boolean types. Differential Revision: https://reviews.llvm.org/D53308 llvm-svn: 345063
Diffstat (limited to 'clang/test/Frontend/fixed_point_to_bool.c')
-rw-r--r--clang/test/Frontend/fixed_point_to_bool.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/clang/test/Frontend/fixed_point_to_bool.c b/clang/test/Frontend/fixed_point_to_bool.c
new file mode 100644
index 00000000000..b5bfa6f3f4c
--- /dev/null
+++ b/clang/test/Frontend/fixed_point_to_bool.c
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - -fpadding-on-unsigned-fixed-point | FileCheck %s
+
+_Bool global_b = 1.0k; // @global_b = {{*.}}global i8 1, align 1
+_Bool global_b2 = 0.0k; // @global_b2 = {{*.}}global i8 0, align 1
+
+void func() {
+ _Accum a = 0.5k;
+ unsigned _Accum ua = 0.5uk;
+ _Bool b;
+
+ // CHECK: store i8 1, i8* %b, align 1
+ // CHECK-NEXT: store i8 0, i8* %b, align 1
+ // CHECK: store i8 1, i8* %b, align 1
+ // CHECK-NEXT: store i8 0, i8* %b, align 1
+ b = 0.5k;
+ b = 0.0k;
+ b = 0.5uk;
+ b = 0.0uk;
+
+ // CHECK-NEXT: store i8 1, i8* %b, align 1
+ // CHECK-NEXT: store i8 0, i8* %b, align 1
+ // CHECK-NEXT: store i8 1, i8* %b, align 1
+ // CHECK-NEXT: store i8 0, i8* %b, align 1
+ b = (_Bool)0.5r;
+ b = (_Bool)0.0r;
+ b = (_Bool)0.5ur;
+ b = (_Bool)0.0ur;
+
+ // CHECK-NEXT: [[ACCUM:%[0-9]+]] = load i32, i32* %a, align 4
+ // CHECK-NEXT: [[NOTZERO:%[0-9]+]] = icmp ne i32 [[ACCUM]], 0
+ // CHECK-NEXT: %frombool = zext i1 [[NOTZERO]] to i8
+ // CHECK-NEXT: store i8 %frombool, i8* %b, align 1
+ b = a;
+
+ // CHECK-NEXT: [[ACCUM:%[0-9]+]] = load i32, i32* %ua, align 4
+ // CHECK-NEXT: [[NOTZERO:%[0-9]+]] = icmp ne i32 [[ACCUM]], 0
+ // CHECK-NEXT: %frombool1 = zext i1 [[NOTZERO]] to i8
+ // CHECK-NEXT: store i8 %frombool1, i8* %b, align 1
+ b = ua;
+
+ // CHECK-NEXT: [[ACCUM:%[0-9]+]] = load i32, i32* %a, align 4
+ // CHECK-NEXT: [[NOTZERO:%[0-9]+]] = icmp ne i32 [[ACCUM]], 0
+ // CHECK-NEXT: br i1 [[NOTZERO]], label %if.then, label %if.end
+ if (a) {
+ }
+
+ // CHECK: [[ACCUM:%[0-9]+]] = load i32, i32* %ua, align 4
+ // CHECK-NEXT: [[NOTZERO:%[0-9]+]] = icmp ne i32 [[ACCUM]], 0
+ // CHECK-NEXT: br i1 [[NOTZERO]], label %if.then{{[0-9]+}}, label %if.end{{[0-9]+}}
+ if (ua) {
+ }
+}
OpenPOWER on IntegriCloud