[llvm-commits] [llvm] r152907 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp test/Transforms/InstCombine/2012-03-16-StoreAlignment.ll

Duncan Sands baldrick at free.fr
Fri Mar 16 01:55:27 PDT 2012


Hi Bill,

> 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>

this seems highly dubious to me.  As far as I can see the problem is that the
front-end generated an 8 byte aligned store to a 4 byte aligned global.  That's
a front-end bug, not something you can work around here.  [I say that the store
is 8 byte aligned because that's the definition of the alignment of a store with
no explicit alignment on it: the ABI alignment of the storee].  Also, it has to
be wrong from another viewpoint: you only fix things up when you can see that
the store is to a global, but the store could still be to that same global if
eg the pointer is the return value of a function call that returns the address
of the global.  But you don't fix things then while presumably you still need
to.

Ciao, Duncan.

>
> Added:
>      llvm/trunk/test/Transforms/InstCombine/2012-03-16-StoreAlignment.ll
> Modified:
>      llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=152907&r1=152906&r2=152907&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Fri Mar 16 02:40:08 2012
> @@ -379,10 +379,22 @@
>       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.
>
> Added: llvm/trunk/test/Transforms/InstCombine/2012-03-16-StoreAlignment.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2012-03-16-StoreAlignment.ll?rev=152907&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/2012-03-16-StoreAlignment.ll (added)
> +++ llvm/trunk/test/Transforms/InstCombine/2012-03-16-StoreAlignment.ll Fri Mar 16 02:40:08 2012
> @@ -0,0 +1,12 @@
> +; RUN: opt<  %s -S -instcombine | FileCheck %s
> +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
> +
> +%0 = type { i32, i8, i8, i8 }
> +
> + at G = external hidden global %0, align 4
> +
> +define void @f1(i64 %a1) nounwind ssp align 2 {
> +; CHECK: store i64 %a1, i64* bitcast (%0* @G to i64*), align 4
> +  store i64 %a1, i64* bitcast (%0* @G to i64*)
> +  ret void
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list