From ff030fd3005e05a2f73a0008faac02063c2582bb Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 16 Mar 2012 07:40:08 +0000 Subject: 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152907 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../InstCombine/InstCombineLoadStoreAlloca.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'lib') 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(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. -- cgit v1.1