[PATCH] Propagate alignment for _Complex
Richard Smith
richard at metafoo.co.uk
Sat Jul 13 18:31:26 PDT 2013
On Sat, Jul 13, 2013 at 11:56 AM, JF Bastien <jfb at google.com> wrote:
> 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.
>
>
> 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");
This is not correct: if the _Complex is overaligned, the alignment of
the 'imag' component will not be the same as the alignment of the
_Complex object.
> }
> 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());
Likewise.
More information about the cfe-commits
mailing list