[cfe-dev] clang not using prefered alignment for 'long long' or 'double'

Robert Lytton robert at xmos.com
Mon Oct 14 05:52:41 PDT 2013

found offending function.

/// getPreferredTypeAlign - Return the "preferred" alignment of the specified
/// type for the current target in bits.  This can be different than the ABI
/// alignment in cases where it is beneficial for performance to overalign
/// a data type.

From: cfe-dev-bounces at cs.uiuc.edu [cfe-dev-bounces at cs.uiuc.edu] on behalf of Robert Lytton [robert at xmos.com]
Sent: 11 October 2013 17:26
To: cfe-dev at cs.uiuc.edu
Subject: [cfe-dev] clang not using prefered alignment for 'long long' or 'double'


I'm working on the XCore target where the target datalayout specifies i64:32:32 and f64:32:32.

The target also specifies:
    LongLongAlign = 32;
    SuitableAlign = 32;
    DoubleAlign = LongDoubleAlign = 32;
(debug confirms that the access functions correctly returning 32)

However compiling:
    void test(){ long long v=0; }
produces 64bit alignment:
    define void @test() #0 {
      %v = alloca i64, align 8
      store i64 0, i64* %v, align 8
      ret void

The following also fails:
    // RUN: %clang_cc1 -triple xcore -verify %s
    // expected-no-diagnostics
    _Static_assert(sizeof(long long) == 8, "sizeof long long is wrong");
    _Static_assert(_Alignof(long long) == 4, "alignof long long is wrong");
    _Static_assert(sizeof(double) == 8, "sizeof double is wrong");
    _Static_assert(_Alignof(double) == 4, "alignof double is wrong");

As the target is very memory sensitive 'align 8' is a wasteful, needless operation and as such is considered an error!

I have tried to trace where the decision to use an alignment of 8 is being made without success so far.
Help or comment most welcome.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131014/259eefee/attachment.html>

More information about the cfe-dev mailing list