[PATCH] D19338: New code hoisting pass based on GVN (optimistic approach)
Sebastian Pop via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 30 08:57:02 PDT 2016
sebpop added a comment.
In http://reviews.llvm.org/D19338#470858, @dberlin wrote:
> I'm very interested to understand where that speedup might come from. Do
> you have a small example of what is happening you can share?
A reduced testcase from that benchmark is @scalarsHoisting.
When embedded in a loop, each iteration gets some benefit from the hoisting.
Also reported as: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70159
From that bug report:
$ cat h.c
float foo_p(float d, float min, float max, float a)
{
float tmin;
float tmax;
float inv = 1.0f / d;
if (inv >= 0) {
tmin = (min - a) * inv;
tmax = (max - a) * inv;
} else {
tmin = (max - a) * inv;
tmax = (min - a) * inv;
}
return tmax + tmin;
}
$ clang h.c -Ofast -S -o-
foo_p: // @foo_p
// BB#0: // %entry
fmov s4, #1.00000000
fdiv s0, s4, s0
fcmp s0, #0.0
fcsel s4, s1, s2, lt
fcsel s1, s2, s1, lt
fsub s1, s1, s3
fsub s2, s4, s3
fadd s1, s2, s1
fmul s0, s1, s0
ret
With the GVN-hoist pass we end up moving the two fmul and fsub up
between fdiv and fcmp, adding more latency between the fdiv and
the user of the result, the fcmp. That allows some processors to
compute in parallel the fdiv, fmuls, and fsubs.
The pass implemented here also fixes the following bugs:
https://llvm.org/bugs/show_bug.cgi?id=12754
https://llvm.org/bugs/show_bug.cgi?id=20242
https://llvm.org/bugs/show_bug.cgi?id=22005
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=5738
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=11820
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=11832
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21485
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=23286
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=29144
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32590
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33315
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=35303
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38204
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43159
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52256
http://reviews.llvm.org/D19338
More information about the llvm-commits
mailing list