aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2012-03-16 07:40:08 +0000
committerBill Wendling <isanbard@gmail.com>2012-03-16 07:40:08 +0000
commitff030fd3005e05a2f73a0008faac02063c2582bb (patch)
tree16958ecd26fcfd24950c12547dfe328114ce5057 /lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
parent5a4c790c06a8884b208611f63d8623da9a93b7e7 (diff)
downloadexternal_llvm-ff030fd3005e05a2f73a0008faac02063c2582bb.zip
external_llvm-ff030fd3005e05a2f73a0008faac02063c2582bb.tar.gz
external_llvm-ff030fd3005e05a2f73a0008faac02063c2582bb.tar.bz2
The alignment of the pointer part of the store instruction may have an
alignment. If that's the case, then we want to make sure that we don't increase the alignment of the store instruction. Because if we increase it to be "more aligned" than the pointer, code-gen may use instructions which require a greater alignment than the pointer guarantees. <rdar://problem/11043589> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152907 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp')
-rw-r--r--lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 7446a51..fa68000 100644
--- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -379,10 +379,22 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) {
unsigned EffectiveStoreAlign = StoreAlign != 0 ? StoreAlign :
TD->getABITypeAlignment(Val->getType());
- if (KnownAlign > EffectiveStoreAlign)
+ if (KnownAlign > EffectiveStoreAlign) {
SI.setAlignment(KnownAlign);
- else if (StoreAlign == 0)
- SI.setAlignment(EffectiveStoreAlign);
+ } else if (StoreAlign == 0) {
+ unsigned PtrAlign = 0;
+ if (GlobalValue *GV = dyn_cast<GlobalValue>(Ptr->stripPointerCasts()))
+ PtrAlign = GV->getAlignment();
+
+ if (PtrAlign != 0 && PtrAlign < EffectiveStoreAlign)
+ // The pointer alignment may be less than the effective store
+ // alignment. If so, then we don't want to increase the alignment here,
+ // since that could lead to code-gen using instructions which require a
+ // higher alignment than the pointer guarantees.
+ SI.setAlignment(PtrAlign);
+ else
+ SI.setAlignment(EffectiveStoreAlign);
+ }
}
// Don't hack volatile/atomic stores.