Skip to content

GCC's vectorization of loop reduction for Zen3 is ~50% faster according to LLVM-MCA #121344

@TiborGY

Description

@TiborGY

I am trying to optimize a few hotspots in a larger body of code, one of which is an RMSD computation implemented as loop reduction, where the loop bounds are completely known at compile time:

double RMSD(const double* const dm1, const double* const dm2){
    const size_t distsPerGeom = (12*11)/2;
    double RMSD = 0.0;
    for (size_t i=0; i<distsPerGeom; i++){
        RMSD += std::pow(dm1[i] - dm2[i], 2);
    }
    return std::sqrt(RMSD / distsPerGeom);
}

What I have found, is that according to LLVM-MCA, GCC is far better at vectorizing this function, 2823 total cycles vs. 4455, see this link:
https://godbolt.org/z/q85rq3bW4

I have not tested this on real HW yet, but I cannot see how this is not indicative of some issue in an LLVM component. Either MCA's cycle counts are wrong for Zen3, or clang is not as good at vectorizing as GCC is.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions