aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-04-25 22:30:02 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-04-25 22:30:02 +0000
commitec9919549095390b5737c561544f8bd49fc894de (patch)
treef872712e7ea6aee1b761842fbd32fb53b0f51ef5 /lib
parent8d8f2c20f3e21c7516e5d27293f08283913904d1 (diff)
Ir-gen the side-effect(s) when __builtin_expect is
constant-folded. // rdar://9330105 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130163 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/CGBuiltin.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp
index e553eb6c27..2971436831 100644
--- a/lib/CodeGen/CGBuiltin.cpp
+++ b/lib/CodeGen/CGBuiltin.cpp
@@ -177,6 +177,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
// See if we can constant fold this builtin. If so, don't emit it at all.
Expr::EvalResult Result;
if (E->Evaluate(Result, CGM.getContext())) {
+ // Short circuiting the __builtin_expect on its 1st argument
+ // must still IR-gen the 1st and 2nd argument's side-effect.
+ if (BuiltinID == Builtin::BI__builtin_expect) {
+ if (E->getArg(0)->HasSideEffects(getContext()))
+ (void)EmitScalarExpr(E->getArg(0));
+ if (E->getArg(1)->HasSideEffects(getContext()))
+ (void)EmitScalarExpr(E->getArg(1));
+ }
+
if (Result.Val.isInt())
return RValue::get(llvm::ConstantInt::get(getLLVMContext(),
Result.Val.getInt()));