diff --git a/src/common/hist_util.cc b/src/common/hist_util.cc index b2a268763b80..e55477c95de2 100644 --- a/src/common/hist_util.cc +++ b/src/common/hist_util.cc @@ -192,11 +192,14 @@ void BuildHistKernel(const std::vector &gpair, } const BinIdxType *gr_index_local = gradient_index + icol_start; + // The trick with pgh_t buffer helps the compiler to generate faster binary. + const float pgh_t[] = {pgh[idx_gh], pgh[idx_gh + 1]}; for (size_t j = 0; j < row_size; ++j) { const uint32_t idx_bin = two * (static_cast(gr_index_local[j]) + (any_missing ? 0 : offsets[j])); - hist_data[idx_bin] += pgh[idx_gh]; - hist_data[idx_bin + 1] += pgh[idx_gh + 1]; + auto hist_local = hist_data + idx_bin; + *(hist_local) += pgh_t[0]; + *(hist_local + 1) += pgh_t[1]; } } }