Rafael Espíndola <[email protected]> writes:
>> That seems like a good idea, but I need some input on where such a test
>> would go and how to structure it. I don't really see any similar tests.
>> From what I can see, EmitBranchOnBoolExpr is basically doing some
>> trivial constant folding so that our codegen at -O0 is reasonable.
>
> If you can get a C testcase it should probably go in clang/test/CodeGen.

What do you think of something like this? I'm not entirely convinced
this is a very good test, but it's hard to write "avoid extraneous basic
blocks" in test form. The best I could think of was avoiding unnecessary
phis.

>From 107920588c4f79c4d2d72709b2fa2e166c82d620 Mon Sep 17 00:00:00 2001
From: Justin Bogner <[email protected]>
Date: Fri, 1 Nov 2013 16:53:45 -0700
Subject: [PATCH] CodeGen: Test that simple expressions are simplified at -O1

---
 test/CodeGen/branch-on-bool.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 test/CodeGen/branch-on-bool.c

diff --git a/test/CodeGen/branch-on-bool.c b/test/CodeGen/branch-on-bool.c
new file mode 100644
index 0000000..78dae1b
--- /dev/null
+++ b/test/CodeGen/branch-on-bool.c
@@ -0,0 +1,22 @@
+// RUN: %clang %s -O0 -emit-llvm -S -o - | FileCheck %s
+
+void foo();
+void bar();
+
+void fold_if(int a, int b) {
+  // CHECK: define {{.*}} @fold_if(
+  // CHECK-NOT: = phi
+  // CHECK: }
+  if (a && b)
+    foo();
+  else
+    bar();
+}
+
+void fold_for(int a, int b) {
+  // CHECK: define {{.*}} @fold_for(
+  // CHECK-NOT: = phi
+  // CHECK: }
+  for (int i = 0; a && i < b; ++i) foo();
+  for (int i = 0; a || i < b; ++i) bar();
+}
-- 
1.8.3.4 (Apple Git-47)

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to