Generalize case for built-in expressions having

side-effect to generate their ir. Not just for
__builtin_expect. // rdar://9330105

llvm-svn: 130172
This commit is contained in:
Fariborz Jahanian 2011-04-25 23:10:07 +00:00
parent 2606f4d6d2
commit 24ac1599fc
1 changed files with 4 additions and 11 deletions

View File

@ -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: {