[llvm-commits] [llvm] r145300 - in /llvm/trunk: lib/CodeGen/SelectionDAG/DAGCombiner.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp test/CodeGen/X86/widen_load-1.ll

Eli Friedman eli.friedman at gmail.com
Mon Nov 28 14:52:25 PST 2011


On Mon, Nov 28, 2011 at 2:37 PM, Evan Cheng <evan.cheng at apple.com> wrote:
> Author: evancheng
> Date: Mon Nov 28 16:37:34 2011
> New Revision: 145300
>
> URL: http://llvm.org/viewvc/llvm-project?rev=145300&view=rev
> Log:
> Revert r145273 and fix in SelectionDAG::InferPtrAlignment() instead.
> Conservatively returns zero when the GV does not specify an alignment nor is it
> initialized. Previously it returns ABI alignment for type of the GV. However, if
> the type is a "packed" type, then the under-specified alignments is attached to
> the load / store instructions. In that case, the alignment of the type cannot be
> trusted.
> rdar://10464621
>
> Modified:
>    llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
>    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
>    llvm/trunk/test/CodeGen/X86/widen_load-1.ll
>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=145300&r1=145299&r2=145300&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Mon Nov 28 16:37:34 2011
> @@ -6206,20 +6206,13 @@
>
>   // Try to infer better alignment information than the load already has.
>   if (OptLevel != CodeGenOpt::None && LD->isUnindexed()) {
> -    unsigned ABIAlign = TLI.getTargetData()->
> -      getABITypeAlignment(LD->getMemoryVT().getTypeForEVT(*DAG.getContext()));
> -    unsigned LDAlign = LD->getAlignment();
> -    // Do not touch loads with explicit alignments that are smaller than ABI
> -    // alignment to avoid breaking loads from "packed" types.
> -    if (!LDAlign || LDAlign >= ABIAlign) {
> -      if (unsigned Align = DAG.InferPtrAlignment(Ptr)) {
> -        if (Align > LDAlign)
> -          return DAG.getExtLoad(LD->getExtensionType(), N->getDebugLoc(),
> -                                LD->getValueType(0),
> -                                Chain, Ptr, LD->getPointerInfo(),
> -                                LD->getMemoryVT(),
> -                                LD->isVolatile(), LD->isNonTemporal(), Align);
> -      }
> +    if (unsigned Align = DAG.InferPtrAlignment(Ptr)) {
> +      if (Align > LD->getAlignment())
> +        return DAG.getExtLoad(LD->getExtensionType(), N->getDebugLoc(),
> +                              LD->getValueType(0),
> +                              Chain, Ptr, LD->getPointerInfo(),
> +                              LD->getMemoryVT(),
> +                              LD->isVolatile(), LD->isNonTemporal(), Align);
>     }
>   }
>
> @@ -6676,18 +6669,11 @@
>
>   // Try to infer better alignment information than the store already has.
>   if (OptLevel != CodeGenOpt::None && ST->isUnindexed()) {
> -    unsigned ABIAlign = TLI.getTargetData()->
> -      getABITypeAlignment(ST->getMemoryVT().getTypeForEVT(*DAG.getContext()));
> -    unsigned STAlign = ST->getAlignment();
> -    // Do not touch stores with explicit alignments that are smaller than ABI
> -    // alignment to avoid breaking stores from "packed" types.
> -    if (!STAlign || STAlign >= ABIAlign) {
> -      if (unsigned Align = DAG.InferPtrAlignment(Ptr)) {
> -        if (Align > STAlign)
> -          return DAG.getTruncStore(Chain, N->getDebugLoc(), Value,
> -                                   Ptr, ST->getPointerInfo(), ST->getMemoryVT(),
> -                                   ST->isVolatile(), ST->isNonTemporal(),Align);
> -      }
> +    if (unsigned Align = DAG.InferPtrAlignment(Ptr)) {
> +      if (Align > ST->getAlignment())
> +        return DAG.getTruncStore(Chain, N->getDebugLoc(), Value,
> +                                 Ptr, ST->getPointerInfo(), ST->getMemoryVT(),
> +                                 ST->isVolatile(), ST->isNonTemporal(), Align);
>     }
>   }
>
>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=145300&r1=145299&r2=145300&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Mon Nov 28 16:37:34 2011
> @@ -6564,7 +6564,11 @@
>         }
>       }
>       if (!Align)
> -        Align = TLI.getTargetData()->getABITypeAlignment(GV->getType());
> +        // Conservatively returns zero here instead of using ABI alignment for
> +        // type of the GV. If the type is a "packed" type, then the under-
> +        // specified alignments is attached to the load / store instructions.
> +        // In that case, the alignment of the type cannot be trusted.
> +        return 0;

Note that the old code here wasn't actually using the ABI alignment of
the type of the GV; it was using the ABI alignment of a pointer.

-Eli




More information about the llvm-commits mailing list