diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-11 07:21:43 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-11 07:21:43 +0000 |
commit | e5ed15195b71b8fa440e67d49db0168bb58e4e8a (patch) | |
tree | 67ccc822f30984bf17d956a816f9d5b64b5795bd /lib/CodeGen/CGExprScalar.cpp | |
parent | 8cb6fb3bd80d0b051f37c31d8658666361b5b7bb (diff) |
finish off codegen support for sub of pointer to functions,
finishing off rdar://6520707
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64295 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprScalar.cpp')
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index b9dcc078d4..a94eef1151 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -965,8 +965,9 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) { uint64_t ElementSize; - // Handle GCC extension for pointer arithmetic on void* types. - if (LHSElementType->isVoidType()) { + // Handle GCC extension for pointer arithmetic on void* and function pointer + // types. + if (LHSElementType->isVoidType() || LHSElementType->isFunctionType()) { ElementSize = 1; } else { ElementSize = CGF.getContext().getTypeSize(LHSElementType) / 8; @@ -977,6 +978,10 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) { RHS = Builder.CreatePtrToInt(RHS, ResultType, "sub.ptr.rhs.cast"); Value *BytesBetween = Builder.CreateSub(LHS, RHS, "sub.ptr.sub"); + // Optimize out the shift for element size of 1. + if (ElementSize == 1) + return BytesBetween; + // HACK: LLVM doesn't have an divide instruction that 'knows' there is no // remainder. As such, we handle common power-of-two cases here to generate // better code. See PR2247. |