diff options
author | Bill Wendling <isanbard@gmail.com> | 2012-03-16 07:40:08 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2012-03-16 07:40:08 +0000 |
commit | ff030fd3005e05a2f73a0008faac02063c2582bb (patch) | |
tree | 16958ecd26fcfd24950c12547dfe328114ce5057 /lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | |
parent | 5a4c790c06a8884b208611f63d8623da9a93b7e7 (diff) |
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.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 7446a51a4d..fa68000df5 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. |