https://bugs.llvm.org/show_bug.cgi?id=47020
Bug ID: 47020
Summary: Reduction loop repeated due to loop invariant variable
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Loop Optimizer
Assignee: unassignedb...@nondot.org
Reporter: llvm-...@redking.me.uk
CC: florian_h...@apple.com, listm...@philipreames.com,
llvm-bugs@lists.llvm.org, spatel+l...@rotateright.com
Pulled out of a code example discussed here:
What Everyone Should Know About How Amazing Compilers Are - Matt Godbolt [C++
on Sea 2019]
https://www.youtube.com/watch?v=w0sz5WbS5AM
#include <vector>
typedef int T;
static T sumA = 0;
static T sumB = 0;
void v3(bool useA, const std::vector<T> &x) {
for(auto v : x) {
if (useA)
sumA += v*v;
else
sumB += v*v;
}
}
-g0 -O3 -march=haswell
https://godbolt.org/z/x79oPx
We repeat the entire reduction loop, with the sumA/sumB result variable
load/store being hoisted out to the start/end - it should be possible to merge
these loops and just select which reference to use before the loop.
If I perform this manually we loose vectorization entirely:
#include <vector>
typedef int T;
static T sumA = 0;
static T sumB = 0;
void v3(bool useA, const std::vector<T> &x) {
T &sum = useA ? sumA : sumB;
for(auto v : x) {
sum += v*v;
}
}
https://godbolt.org/z/168GMz
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs