summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-06-17 17:47:24 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-06-17 17:47:24 +0000
commit3370c20c7e3c21d487de1177a5b4e1e9971a8764 (patch)
tree75acb9019bbeaf568ef0ef5d6c79eff9edb1b225 /clang/lib
parent9f86baebe06e77fac1174717b926fb99cfe092ef (diff)
downloadbcm5719-llvm-3370c20c7e3c21d487de1177a5b4e1e9971a8764.tar.gz
bcm5719-llvm-3370c20c7e3c21d487de1177a5b4e1e9971a8764.zip
[CodeGen] Use pointer-sized integers for ptrtoint sources
Given something like: void *v = (void *)100; We need to synthesize a ptrtoint operation from 100. During constant emission, we choose i64 as the type for our constant because it guaranteed not to drop any bits from our CharUnits representation of the value. However, this is suboptimal for 32-bit targets: LLVM passes like GlobalOpt will get confused by these sorts of casts resulting in pessimization. Instead, make sure the ptrtoint operand has a pointer-sized integer type. llvm-svn: 273020
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/CGExprConstant.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index d64c5876ee2..8ad1a4d29cd 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1314,8 +1314,14 @@ llvm::Constant *CodeGenModule::EmitConstantValue(const APValue &Value,
// Convert to the appropriate type; this could be an lvalue for
// an integer.
- if (isa<llvm::PointerType>(DestTy))
+ if (isa<llvm::PointerType>(DestTy)) {
+ // Convert the integer to a pointer-sized integer before converting it
+ // to a pointer.
+ C = llvm::ConstantExpr::getIntegerCast(
+ C, getDataLayout().getIntPtrType(DestTy),
+ /*isSigned=*/false);
return llvm::ConstantExpr::getIntToPtr(C, DestTy);
+ }
// If the types don't match this should only be a truncate.
if (C->getType() != DestTy)
OpenPOWER on IntegriCloud