summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2018-11-20 08:53:30 +0000
committerBill Wendling <isanbard@gmail.com>2018-11-20 08:53:30 +0000
commit107b0e9881c87dba9f51109bae70b63d9e444546 (patch)
treec2bcc110804ddf7dca9704e3a47a2f26a6e2bcd5 /clang/lib/CodeGen
parentcabb36d38d9e71610c7767a22477576aa8a4d9fa (diff)
downloadbcm5719-llvm-107b0e9881c87dba9f51109bae70b63d9e444546.tar.gz
bcm5719-llvm-107b0e9881c87dba9f51109bae70b63d9e444546.zip
Use is.constant intrinsic for __builtin_constant_p
Summary: A __builtin_constant_p may end up with a constant after inlining. Use the is.constant intrinsic if it's a variable that's in a context where it may resolve to a constant, e.g., an argument to a function after inlining. Reviewers: rsmith, shafik Subscribers: jfb, kristina, cfe-commits, nickdesaulniers, jyknight Differential Revision: https://reviews.llvm.org/D54355 llvm-svn: 347294
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGBuiltin.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5291dc9a488..4e639e98290 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1926,6 +1926,26 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
case Builtin::BI__builtin_rotateright64:
return emitRotate(E, true);
+ case Builtin::BI__builtin_constant_p: {
+ llvm::Type *ResultType = ConvertType(E->getType());
+ if (CGM.getCodeGenOpts().OptimizationLevel == 0)
+ // At -O0, we don't perform inlining, so we don't need to delay the
+ // processing.
+ return RValue::get(ConstantInt::get(ResultType, 0));
+ if (auto *DRE = dyn_cast<DeclRefExpr>(E->getArg(0)->IgnoreImplicit())) {
+ auto DREType = DRE->getType();
+ if (DREType->isAggregateType() || DREType->isFunctionType())
+ return RValue::get(ConstantInt::get(ResultType, 0));
+ }
+ Value *ArgValue = EmitScalarExpr(E->getArg(0));
+ llvm::Type *ArgType = ArgValue->getType();
+
+ Value *F = CGM.getIntrinsic(Intrinsic::is_constant, ArgType);
+ Value *Result = Builder.CreateCall(F, ArgValue);
+ if (Result->getType() != ResultType)
+ Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true);
+ return RValue::get(Result);
+ }
case Builtin::BI__builtin_object_size: {
unsigned Type =
E->getArg(1)->EvaluateKnownConstInt(getContext()).getZExtValue();
OpenPOWER on IntegriCloud