summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGen/builtin-constant-p.c
diff options
context:
space:
mode:
authorJoerg Sonnenberger <joerg@bec.de>2019-10-13 22:33:46 +0000
committerJoerg Sonnenberger <joerg@bec.de>2019-10-13 22:33:46 +0000
commit529f4ed401ea9761461fb42b1efa552c320c40fb (patch)
tree2d97732ca35e404a576dd951125107f6e1cb9d07 /clang/test/CodeGen/builtin-constant-p.c
parentf79716774a037d5c9ab41497227394994a5346a7 (diff)
downloadbcm5719-llvm-529f4ed401ea9761461fb42b1efa552c320c40fb.tar.gz
bcm5719-llvm-529f4ed401ea9761461fb42b1efa552c320c40fb.zip
Improve __builtin_constant_p lowering
__builtin_constant_p used to be short-cut evaluated to false when building with -O0. This is undesirable as it means that constant folding in the front-end can give different results than folding in the back-end. It can also create conditional branches on constant conditions that don't get folded away. With the pending improvements to the llvm.is.constant handling on the LLVM side, the short-cut is no longer useful. Adjust various codegen tests to not depend on the short-cut or the backend optimisations. Differential Revision: https://reviews.llvm.org/D67638 llvm-svn: 374742
Diffstat (limited to 'clang/test/CodeGen/builtin-constant-p.c')
-rw-r--r--clang/test/CodeGen/builtin-constant-p.c127
1 files changed, 46 insertions, 81 deletions
diff --git a/clang/test/CodeGen/builtin-constant-p.c b/clang/test/CodeGen/builtin-constant-p.c
index 36c45988d64..7965dbe93f9 100644
--- a/clang/test/CodeGen/builtin-constant-p.c
+++ b/clang/test/CodeGen/builtin-constant-p.c
@@ -1,12 +1,8 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O2 | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O0 | FileCheck --check-prefix=O0 %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-llvm-optzns -o - %s -O2 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-llvm-optzns -o - %s -O0 | FileCheck %s
int a = 42;
-inline int bcp(int x) {
- return __builtin_constant_p(x);
-}
-
/* --- Compound literals */
struct foo { int x, y; };
@@ -15,85 +11,56 @@ int y;
struct foo f = (struct foo){ __builtin_constant_p(y), 42 };
struct foo test0(int expr) {
- // CHECK: define i64 @test0(i32 %expr)
- // CHECK: call i1 @llvm.is.constant.i32(i32 %expr)
+ // CHECK-LABEL: test0
+ // CHECK: call i1 @llvm.is.constant.i32
struct foo f = (struct foo){ __builtin_constant_p(expr), 42 };
return f;
}
/* --- Pointer types */
-inline int test1_i(int *x) {
- return *x;
-}
-
int test1() {
- // CHECK: define i32 @test1
- // CHECK: add nsw i32 %0, -13
- // CHECK-NEXT: call i1 @llvm.is.constant.i32(i32 %sub)
- return bcp(test1_i(&a) - 13);
-}
-
-int test2() {
- // CHECK: define i32 @test2
+ // CHECK-LABEL: test1
// CHECK: ret i32 0
return __builtin_constant_p(&a - 13);
}
-inline int test3_i(int *x) {
- return 42;
-}
-
-int test3() {
- // CHECK: define i32 @test3
- // CHECK: ret i32 1
- return bcp(test3_i(&a) - 13);
-}
-
/* --- Aggregate types */
int b[] = {1, 2, 3};
-int test4() {
- // CHECK: define i32 @test4
+int test2() {
+ // CHECK-LABEL: test2
// CHECK: ret i32 0
return __builtin_constant_p(b);
}
-const char test5_c[] = {1, 2, 3, 0};
+const char test3_c[] = {1, 2, 3, 0};
-int test5() {
- // CHECK: define i32 @test5
+int test3() {
+ // CHECK-LABEL: test3
// CHECK: ret i32 0
- return __builtin_constant_p(test5_c);
+ return __builtin_constant_p(test3_c);
}
-inline char test6_i(const char *x) {
+inline char test4_i(const char *x) {
return x[1];
}
-int test6() {
- // CHECK: define i32 @test6
+int test4() {
+ // CHECK: define i32 @test4
// CHECK: ret i32 0
- return __builtin_constant_p(test6_i(test5_c));
-}
-
-/* --- Non-constant global variables */
-
-int test7() {
- // CHECK: define i32 @test7
- // CHECK: call i1 @llvm.is.constant.i32(i32 %0)
- return bcp(a);
+ return __builtin_constant_p(test4_i(test3_c));
}
/* --- Constant global variables */
const int c = 42;
-int test8() {
- // CHECK: define i32 @test8
+int test5() {
+ // CHECK-LABEL: test5
// CHECK: ret i32 1
- return bcp(c);
+ return __builtin_constant_p(c);
}
/* --- Array types */
@@ -101,34 +68,34 @@ int test8() {
int arr[] = { 1, 2, 3 };
const int c_arr[] = { 1, 2, 3 };
-int test9() {
- // CHECK: define i32 @test9
- // CHECK: call i1 @llvm.is.constant.i32(i32 %0)
+int test6() {
+ // CHECK-LABEL: test6
+ // CHECK: call i1 @llvm.is.constant.i32
return __builtin_constant_p(arr[2]);
}
-int test10() {
- // CHECK: define i32 @test10
- // CHECK: ret i32 1
+int test7() {
+ // CHECK-LABEL: test7
+ // CHECK: call i1 @llvm.is.constant.i32
return __builtin_constant_p(c_arr[2]);
}
-int test11() {
- // CHECK: define i32 @test11
+int test8() {
+ // CHECK-LABEL: test8
// CHECK: ret i32 0
return __builtin_constant_p(c_arr);
}
/* --- Function pointers */
-int test12() {
- // CHECK: define i32 @test12
+int test9() {
+ // CHECK-LABEL: test9
// CHECK: ret i32 0
- return __builtin_constant_p(&test10);
+ return __builtin_constant_p(&test9);
}
-int test13() {
- // CHECK: define i32 @test13
+int test10() {
+ // CHECK-LABEL: test10
// CHECK: ret i32 1
return __builtin_constant_p(&test10 != 0);
}
@@ -155,33 +122,31 @@ extern fn_p *dest_p;
static void src_fn(void) {
}
-void test14() {
+void test11() {
assign(dest_p, src_fn);
}
-extern int test15_v;
+extern int test12_v;
-struct { const char *t; int a; } test15[] = {
- { "tag", __builtin_constant_p(test15_v) && !test15_v ? 1 : 0 }
+struct { const char *t; int a; } test12[] = {
+ { "tag", __builtin_constant_p(test12_v) && !test12_v ? 1 : 0 }
};
-extern char test16_v;
-struct { int a; } test16 = { __builtin_constant_p(test16_v) };
+extern char test13_v;
+struct { int a; } test13 = { __builtin_constant_p(test13_v) };
-extern unsigned long long test17_v;
+extern unsigned long long test14_v;
-void test17() {
- // O0: define void @test17
- // O0: call void asm sideeffect "", {{.*}}(i32 -1)
- // CHECK: define void @test17
+void test14() {
+ // CHECK-LABEL: test14
// CHECK: call void asm sideeffect "", {{.*}}(i32 -1)
- __asm__ __volatile__("" :: "n"( (__builtin_constant_p(test17_v) || 0) ? 1 : -1));
+ __asm__ __volatile__("" :: "n"( (__builtin_constant_p(test14_v) || 0) ? 1 : -1));
}
-int test18_f();
-// CHECK: define void @test18
-// CHECK-NOT: call {{.*}}test18_f
-void test18() {
+int test15_f();
+// CHECK-LABEL: define void @test15
+// CHECK-NOT: call {{.*}}test15_f
+void test15() {
int a, b;
- (void)__builtin_constant_p((a = b, test18_f()));
+ (void)__builtin_constant_p((a = b, test15_f()));
}
OpenPOWER on IntegriCloud