summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorAlina Sbirlea <asbirlea@google.com>2016-07-11 20:46:17 +0000
committerAlina Sbirlea <asbirlea@google.com>2016-07-11 20:46:17 +0000
commit327955e057a7bc7ae68ad5baac0ba818dc5f0144 (patch)
tree27d199a9e11dd463f2d8df3d20725d3ef9084e12 /llvm/lib/Transforms
parentcfbac5f3612544f8acd63cba72dd44484a393cd4 (diff)
downloadbcm5719-llvm-327955e057a7bc7ae68ad5baac0ba818dc5f0144.tar.gz
bcm5719-llvm-327955e057a7bc7ae68ad5baac0ba818dc5f0144.zip
Add TLI.allowsMisalignedMemoryAccesses to LoadStoreVectorizer
Summary: Extend TTI to access TLI.allowsMisalignedMemoryAccesses(). Check condition when vectorizing load and store chains. Add additional parameters: AddressSpace, Alignment, Fast. Reviewers: llvm-commits, jlebar Subscribers: arsenm, mzolotukhin Differential Revision: http://reviews.llvm.org/D21935 llvm-svn: 275100
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp58
1 files changed, 34 insertions, 24 deletions
diff --git a/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp b/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
index 8166361636f..9c581a4603b 100644
--- a/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
@@ -127,6 +127,10 @@ private:
/// Vectorizes the store instructions in Chain.
bool vectorizeStoreChain(ArrayRef<Value *> Chain);
+
+ /// Check if this load/store access is misaligned accesses
+ bool accessIsMisaligned(unsigned SzInBytes, unsigned AddressSpace,
+ unsigned Alignment);
};
class LoadStoreVectorizer : public FunctionPass {
@@ -692,18 +696,16 @@ bool Vectorizer::vectorizeStoreChain(ArrayRef<Value *> Chain) {
unsigned Alignment = getAlignment(S0);
// If the store is going to be misaligned, don't vectorize it.
- // TODO: Check TLI.allowsMisalignedMemoryAccess
- if ((Alignment % SzInBytes) != 0 && (Alignment % TargetBaseAlign) != 0) {
- if (S0->getPointerAddressSpace() == 0) {
- // If we're storing to an object on the stack, we control its alignment,
- // so we can cheat and change it!
- Value *V = GetUnderlyingObject(S0->getPointerOperand(), DL);
- if (AllocaInst *AI = dyn_cast_or_null<AllocaInst>(V)) {
- AI->setAlignment(TargetBaseAlign);
- Alignment = TargetBaseAlign;
- } else {
- return false;
- }
+ if (accessIsMisaligned(SzInBytes, AS, Alignment)) {
+ if (S0->getPointerAddressSpace() != 0)
+ return false;
+
+ // If we're storing to an object on the stack, we control its alignment,
+ // so we can cheat and change it!
+ Value *V = GetUnderlyingObject(S0->getPointerOperand(), DL);
+ if (AllocaInst *AI = dyn_cast_or_null<AllocaInst>(V)) {
+ AI->setAlignment(TargetBaseAlign);
+ Alignment = TargetBaseAlign;
} else {
return false;
}
@@ -821,18 +823,16 @@ bool Vectorizer::vectorizeLoadChain(ArrayRef<Value *> Chain) {
unsigned Alignment = getAlignment(L0);
// If the load is going to be misaligned, don't vectorize it.
- // TODO: Check TLI.allowsMisalignedMemoryAccess and remove TargetBaseAlign.
- if ((Alignment % SzInBytes) != 0 && (Alignment % TargetBaseAlign) != 0) {
- if (L0->getPointerAddressSpace() == 0) {
- // If we're loading from an object on the stack, we control its alignment,
- // so we can cheat and change it!
- Value *V = GetUnderlyingObject(L0->getPointerOperand(), DL);
- if (AllocaInst *AI = dyn_cast_or_null<AllocaInst>(V)) {
- AI->setAlignment(TargetBaseAlign);
- Alignment = TargetBaseAlign;
- } else {
- return false;
- }
+ if (accessIsMisaligned(SzInBytes, AS, Alignment)) {
+ if (L0->getPointerAddressSpace() != 0)
+ return false;
+
+ // If we're loading from an object on the stack, we control its alignment,
+ // so we can cheat and change it!
+ Value *V = GetUnderlyingObject(L0->getPointerOperand(), DL);
+ if (AllocaInst *AI = dyn_cast_or_null<AllocaInst>(V)) {
+ AI->setAlignment(TargetBaseAlign);
+ Alignment = TargetBaseAlign;
} else {
return false;
}
@@ -915,3 +915,13 @@ bool Vectorizer::vectorizeLoadChain(ArrayRef<Value *> Chain) {
NumScalarsVectorized += Chain.size();
return true;
}
+
+bool Vectorizer::accessIsMisaligned(unsigned SzInBytes, unsigned AddressSpace,
+ unsigned Alignment) {
+ bool Fast = false;
+ bool Allows = TTI.allowsMisalignedMemoryAccesses(SzInBytes * 8, AddressSpace,
+ Alignment, &Fast);
+ // TODO: Remove TargetBaseAlign
+ return !(Allows && Fast) && (Alignment % SzInBytes) != 0 &&
+ (Alignment % TargetBaseAlign) != 0;
+}
OpenPOWER on IntegriCloud