[cfe-commits] r129649 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/conditional.c
Chris Lattner
sabre at nondot.org
Sat Apr 16 16:15:35 PDT 2011
Author: lattner
Date: Sat Apr 16 18:15:35 2011
New Revision: 129649
URL: http://llvm.org/viewvc/llvm-project?rev=129649&view=rev
Log:
fix rdar://9289603 - clang should fold trivial ?: for enums as well as integer constants into select at -O0
by making the isCheapEnoughToEvaluateUnconditionally predicate handle anything that folds to a constant. In particular, we now fold enums.
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGen/conditional.c
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=129649&r1=129648&r2=129649&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sat Apr 16 18:15:35 2011
@@ -2401,9 +2401,8 @@
CodeGenFunction &CGF) {
E = E->IgnoreParens();
- // TODO: Allow anything we can constant fold to an integer or fp constant.
- if (isa<IntegerLiteral>(E) || isa<CharacterLiteral>(E) ||
- isa<FloatingLiteral>(E))
+ // Anything that is an integer or floating point constant is fine.
+ if (E->isConstantInitializer(CGF.getContext(), false))
return true;
// Non-volatile automatic variables too, to get "cond ? X : Y" where
Modified: cfe/trunk/test/CodeGen/conditional.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/conditional.c?rev=129649&r1=129648&r2=129649&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/conditional.c (original)
+++ cfe/trunk/test/CodeGen/conditional.c Sat Apr 16 18:15:35 2011
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm %s -o %t
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
float test1(int cond, float a, float b) {
return cond ? a : b;
@@ -47,3 +47,22 @@
p ? p : test9spare();
}
+// CHECK: @test10
+// CHECK: select i1 {{.*}}, i32 4, i32 5
+int test10(int c) {
+ return c ? 4 : 5;
+}
+enum { Gronk = 5 };
+
+// rdar://9289603
+// CHECK: @test11
+// CHECK: select i1 {{.*}}, i32 4, i32 5
+int test11(int c) {
+ return c ? 4 : Gronk;
+}
+
+// CHECK: @test12
+// CHECK: select i1 {{.*}}, double 4.0{{.*}}, double 2.0
+double test12(int c) {
+ return c ? 4.0 : 2.0;
+}
More information about the cfe-commits
mailing list