diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 29714368317d..7a0c8da50248 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -176,16 +176,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, unsigned BuiltinID, const CallExpr *E) { // 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 (E->Evaluate(Result, CGM.getContext()) && + !Result.hasSideEffects()) { if (Result.Val.isInt()) return RValue::get(llvm::ConstantInt::get(getLLVMContext(), Result.Val.getInt())); @@ -321,9 +313,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, } case Builtin::BI__builtin_expect: { // FIXME: pass expect through to LLVM + Value *ArgValue = EmitScalarExpr(E->getArg(0)); if (E->getArg(1)->HasSideEffects(getContext())) (void)EmitScalarExpr(E->getArg(1)); - return RValue::get(EmitScalarExpr(E->getArg(0))); + return RValue::get(ArgValue); } case Builtin::BI__builtin_bswap32: case Builtin::BI__builtin_bswap64: {