Skip to content

Commit a155a35

Browse files
[flang] Control alignment of constant folded reals
When REAL types are constant folded, the underneath implementation uses arrays of integers. Ensure that these arrays are properly aligned. This matters when building flang with clang. In some cases, the resulting code for flang compiler ended up using SSE2 aligned load instructions for REAL(16) constant folding on x86_64, and these instructions require that the values are loaded from the aligned addresses.
1 parent b7c14b6 commit a155a35

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

flang/include/flang/Evaluate/integer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class Integer {
7474
static_assert(std::is_unsigned_v<BigPart>);
7575
static_assert(CHAR_BIT * sizeof(BigPart) >= 2 * partBits);
7676
static constexpr bool littleEndian{IS_LITTLE_ENDIAN};
77+
static constexpr int alignment{ALIGNMENT};
7778

7879
private:
7980
static constexpr int maxPartBits{CHAR_BIT * sizeof(Part)};

flang/include/flang/Evaluate/real.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ template <typename WORD, int PREC> class Real {
490490
bool isNegative, int exponent, const Fraction &, Rounding, RoundingBits,
491491
bool multiply = false);
492492

493-
Word word_{}; // an Integer<>
493+
alignas(Word::alignment / 8) Word word_{}; // an Integer<>
494494
};
495495

496496
extern template class Real<Integer<16>, 11>; // IEEE half format

0 commit comments

Comments
 (0)