[flang] Fix clang performance problem with new code

Original-commit: flang-compiler/f18@b70cac3ba8
Reviewed-on: https://github.com/flang-compiler/f18/pull/785
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2019-10-21 14:57:48 -07:00
parent dc4fac5634
commit 4f761d601e
2 changed files with 8 additions and 3 deletions

View File

@ -19,7 +19,7 @@
#define FORTRAN_COMMON_UINT128_H_
#ifndef AVOID_NATIVE_UINT128_T
#define AVOID_NATIVE_UINT128_T 1 // for testing purposes (pmk!)
#define AVOID_NATIVE_UINT128_T 1 // always use this code for now for testing
#endif
#include "leading-zero-bit-count.h"

View File

@ -36,7 +36,7 @@ private:
static_assert(std::is_unsigned_v<type>);
static const int bits{static_cast<int>(8 * sizeof(type))};
static_assert(bits <= 64);
using Big = std::conditional_t<(bits <= 32), std::uint64_t, uint128_t>;
using Big = HostUnsignedIntType<bits * 2>;
public:
static constexpr FixedPointReciprocal For(type n) {
@ -71,7 +71,12 @@ inline constexpr UINT DivideUnsignedBy(UINT n) {
if constexpr (std::is_same_v<UINT, uint128_t>) {
return n / static_cast<UINT>(DENOM);
} else {
return FixedPointReciprocal<UINT>::For(DENOM).Divide(n);
// G++ can recognize that the reciprocal is a compile-time
// constant when For() is called inline, but clang requires
// a constexpr variable definition to force compile-time
// evaluation of the reciprocal.
constexpr auto recip{FixedPointReciprocal<UINT>::For(DENOM)};
return recip.Divide(n);
}
}
}