diff options
author | Dan Gohman <gohman@apple.com> | 2010-02-10 06:13:07 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-02-10 06:13:07 +0000 |
commit | 183a423af93fc76f11edfb74a02bc35e17876e5c (patch) | |
tree | 399a81df6380449bed311a52a5d7a0747340fa0c /llvm/lib/VMCore/ConstantFold.cpp | |
parent | e69b99baafc4cf88d2c600da8d637073abe24704 (diff) | |
download | bcm5719-llvm-183a423af93fc76f11edfb74a02bc35e17876e5c.tar.gz bcm5719-llvm-183a423af93fc76f11edfb74a02bc35e17876e5c.zip |
Canonicalize sizeof and alignof on pointer types to a canonical
pointer type.
llvm-svn: 95769
Diffstat (limited to 'llvm/lib/VMCore/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/VMCore/ConstantFold.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp index a97396e1249..5c117d8a181 100644 --- a/llvm/lib/VMCore/ConstantFold.cpp +++ b/llvm/lib/VMCore/ConstantFold.cpp @@ -361,6 +361,15 @@ static Constant *getFoldedSizeOf(const Type *Ty, const Type *DestTy, } } + // Pointer size doesn't depend on the pointee type, so canonicalize them + // to an arbitrary pointee. + if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) + if (!PTy->getElementType()->isInteger(1)) + return + getFoldedSizeOf(PointerType::get(IntegerType::get(PTy->getContext(), 1), + PTy->getAddressSpace()), + DestTy, true); + // If there's no interesting folding happening, bail so that we don't create // a constant that looks like it needs folding but really doesn't. if (!Folded) @@ -417,6 +426,16 @@ static Constant *getFoldedAlignOf(const Type *Ty, const Type *DestTy, return MemberAlign; } + // Pointer alignment doesn't depend on the pointee type, so canonicalize them + // to an arbitrary pointee. + if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) + if (!PTy->getElementType()->isInteger(1)) + return + getFoldedAlignOf(PointerType::get(IntegerType::get(PTy->getContext(), + 1), + PTy->getAddressSpace()), + DestTy, true); + // If there's no interesting folding happening, bail so that we don't create // a constant that looks like it needs folding but really doesn't. if (!Folded) |