Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

In case of -ffast-math, the Loop Vectorizer can generate slower code than the SLP vectorizer #33217

Open Quuxplusone opened 7 years ago

Quuxplusone commented 7 years ago
Bugzilla Link PR34245
Status NEW
Importance P enhancement
Reported by Roman Gareev (gareevroman@gmail.com)
Reported on 2017-08-19 10:46:03 -0700
Last modified on 2019-09-13 08:00:43 -0700
Version trunk
Hardware PC Linux
CC florian_hahn@apple.com, gareevroman@gmail.com, hfinkel@anl.gov, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
Fixed by commit(s)
Attachments with-ffast-math.ll (33591 bytes, text/plain)
without-ffast-math.ll (33277 bytes, text/plain)
with-ffast-math-IR.ll (105486 bytes, text/plain)
without-ffast-math-IR.ll (33272 bytes, text/plain)
Blocks
Blocked by
See also
Created attachment 19009
Code generated using the -ffast-math option.

In case of  -ffast-math, the Loop Vectorizer can generate mis-optimized code.

For example, in case of "opt without-ffast-math.ll -loop-vectorize -S", I get
without-ffast-math-result.ll, which contains 478 lines of code.

However,, if I run "opt with-ffast-math.ll -loop-vectorize -S", I get with-
ffast-math-result.ll, which contains 1432 lines of code and leads to execution
time regression.
Quuxplusone commented 7 years ago

Attached with-ffast-math.ll (33591 bytes, text/plain): Code generated using the -ffast-math option.

Quuxplusone commented 7 years ago

Attached without-ffast-math.ll (33277 bytes, text/plain): Code generated without the -ffast-math option.

Quuxplusone commented 7 years ago

Attached with-ffast-math-IR.ll (105486 bytes, text/plain): Code generated by the Loop Vectorizer.

Quuxplusone commented 7 years ago

Attached without-ffast-math-IR.ll (33272 bytes, text/plain): Code generated by the Loop Vectorizer.

Quuxplusone commented 7 years ago

without-ffast-math.ll can be optimized using the SLP Vectorizer to get the optimized GEMM.

Quuxplusone commented 7 years ago

A few of things....

First, in our terminology, "misoptimize" means that the code is transformed in a semantically-incorrect manner (i.e. it produces the wrong answer). If the code is only slower, that's just a performance regression.

Second, your metric of "more lines of code" is not necessarily correlated with performance. The vectorizer might generate a vectorized version in addition to the original loop (now used to handle tail iterations), and it might also unroll the loop, and while the result might be more IR, that has very little to do with whether it is faster or slower. The problem here might be aliasing (leading to an expensive runtime check).

Third, you've not provided any details on the platform for which you've compiled. You've also not detailed the size of the regression.

Quuxplusone commented 7 years ago
Ok. Thanks for the comments!

> Third, you've not provided any details on the platform for which you've
compiled.
The OS is Ubuntu 16.04.3 LTS. The CPU is Intel(R) Core(TM) i7-7700 CPU @
3.60GHz Kaby Lake. The information about the CPU architecture obtained using
lscpu:

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    2
Core(s) per socket:    4
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 158
Model name:            Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
Stepping:              9
CPU MHz:               800.244
CPU max MHz:           4200,0000
CPU min MHz:           800,0000
BogoMIPS:              7201.02
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              8192K
NUMA node0 CPU(s):     0-7
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx
pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl
xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl
vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe
popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch
epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle
avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt xsaveopt xsavec
xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp

> You've also not detailed the size of the regression.
In case the Loop Vectorizer is disabled using the -fno-vectorize or -ffast-math
is not used, I get 36,3 GFLOP/s. Otherwise, I get 15,52 GFLOP/s.