[PATCH] Propagate alignment for _Complex

Hal Finkel hfinkel at anl.gov
Sat Jul 13 18:06:04 PDT 2013


----- Original Message -----
> This looks like a small oversight that I ran into while running GCC's
> torture tests and modifying LLVM: alignment for _Complex isn't
> propagated to volatile load/store.

This would certainly require a test case.

 -Hal

> 
> 
> diff --git a/lib/CodeGen/CGExprComplex.cpp
> b/lib/CodeGen/CGExprComplex.cpp
> index e4b2f3b..9b0a02f 100644
> --- a/lib/CodeGen/CGExprComplex.cpp
> +++ b/lib/CodeGen/CGExprComplex.cpp
> @@ -297,19 +297,22 @@ ComplexPairTy
> ComplexExprEmitter::EmitLoadOfLValue(LValue lvalue) {
> 
>    llvm::Value *SrcPtr = lvalue.getAddress();
>    bool isVolatile = lvalue.isVolatileQualified();
> +  unsigned Align = lvalue.getAlignment().getQuantity();
> 
>    llvm::Value *Real=0, *Imag=0;
> 
>    if (!IgnoreReal || isVolatile) {
>      llvm::Value *RealP = Builder.CreateStructGEP(SrcPtr, 0,
>                                                   SrcPtr->getName() +
>                                                   ".realp");
> -    Real = Builder.CreateLoad(RealP, isVolatile, SrcPtr->getName() +
> ".real");
> +    Real = Builder.CreateAlignedLoad(RealP, Align, isVolatile,
> +                                     SrcPtr->getName() + ".real");
>    }
> 
>    if (!IgnoreImag || isVolatile) {
>      llvm::Value *ImagP = Builder.CreateStructGEP(SrcPtr, 1,
>                                                   SrcPtr->getName() +
>                                                   ".imagp");
> -    Imag = Builder.CreateLoad(ImagP, isVolatile, SrcPtr->getName() +
> ".imag");
> +    Imag = Builder.CreateAlignedLoad(ImagP, Align, isVolatile,
> +                                     SrcPtr->getName() + ".imag");
>    }
>    return ComplexPairTy(Real, Imag);
>  }
> @@ -325,10 +328,12 @@ void
> ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val,
>    llvm::Value *Ptr = lvalue.getAddress();
>    llvm::Value *RealPtr = Builder.CreateStructGEP(Ptr, 0, "real");
>    llvm::Value *ImagPtr = Builder.CreateStructGEP(Ptr, 1, "imag");
> +  unsigned Align = lvalue.getAlignment().getQuantity();
> 
> -  // TODO: alignment
> -  Builder.CreateStore(Val.first, RealPtr,
> lvalue.isVolatileQualified());
> -  Builder.CreateStore(Val.second, ImagPtr,
> lvalue.isVolatileQualified());
> +  Builder.CreateAlignedStore(Val.first, RealPtr, Align,
> +                             lvalue.isVolatileQualified());
> +  Builder.CreateAlignedStore(Val.second, ImagPtr, Align,
> +                             lvalue.isVolatileQualified());
>  }
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory



More information about the cfe-commits mailing list