summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/ConstantFold.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-02-10 06:13:07 +0000
committerDan Gohman <gohman@apple.com>2010-02-10 06:13:07 +0000
commit183a423af93fc76f11edfb74a02bc35e17876e5c (patch)
tree399a81df6380449bed311a52a5d7a0747340fa0c /llvm/lib/VMCore/ConstantFold.cpp
parente69b99baafc4cf88d2c600da8d637073abe24704 (diff)
downloadbcm5719-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.cpp19
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)
OpenPOWER on IntegriCloud