[ppc] LLVM built 470.lbm is 9.5% slower than gcc on power8
| Bugzilla Link | 25219 |
| Resolution | FIXED |
| Resolved on | Aug 23, 2017 12:51 |
| Version | trunk |
| OS | Linux |
| CC | @echristo,@hfinkel,@lei137 |
Extended Description
The following compiler options are used -fno-strict-aliasing -O2 -m64 -mvsx -mcpu=power8 -ffp-contract=fast
more than 98% of execution time is in function LBM_performStreamCollide, it contains a single loop, related code is:
void LBM_performStreamCollide( LBM_Grid srcGrid, LBM_Grid dstGrid ) { for (...) { ...
ux = + SRC_E ( srcGrid ) - SRC_W ( srcGrid )
+ SRC_NE( srcGrid ) - SRC_NW( srcGrid )
+ SRC_SE( srcGrid ) - SRC_SW( srcGrid )
+ SRC_ET( srcGrid ) + SRC_EB( srcGrid )
- SRC_WT( srcGrid ) - SRC_WB( srcGrid );
uy = + SRC_N ( srcGrid ) - SRC_S ( srcGrid )
+ SRC_NE( srcGrid ) + SRC_NW( srcGrid )
- SRC_SE( srcGrid ) - SRC_SW( srcGrid )
+ SRC_NT( srcGrid ) + SRC_NB( srcGrid )
- SRC_ST( srcGrid ) - SRC_SB( srcGrid );
uz = + SRC_T ( srcGrid ) - SRC_B ( srcGrid )
+ SRC_NT( srcGrid ) - SRC_NB( srcGrid )
+ SRC_ST( srcGrid ) - SRC_SB( srcGrid )
+ SRC_ET( srcGrid ) - SRC_EB( srcGrid )
+ SRC_WT( srcGrid ) - SRC_WB( srcGrid );
ux /= rho;
uy /= rho;
uz /= rho;
if( TEST_FLAG_SWEEP( srcGrid, ACCEL )) {
ux = 0.005;
uy = 0.002;
uz = 0.000;
}
...
} }
LLVM tranforms the code into
if( TEST_FLAG_SWEEP( srcGrid, ACCEL )) {
ux = + SRC_E ( srcGrid ) - SRC_W ( srcGrid )
+ SRC_NE( srcGrid ) - SRC_NW( srcGrid )
+ SRC_SE( srcGrid ) - SRC_SW( srcGrid )
+ SRC_ET( srcGrid ) + SRC_EB( srcGrid )
- SRC_WT( srcGrid ) - SRC_WB( srcGrid );
ux /= rho;
}
else
ux = 0.005;
if( TEST_FLAG_SWEEP( srcGrid, ACCEL )) {
uy = + SRC_N ( srcGrid ) - SRC_S ( srcGrid )
+ SRC_NE( srcGrid ) + SRC_NW( srcGrid )
- SRC_SE( srcGrid ) - SRC_SW( srcGrid )
+ SRC_NT( srcGrid ) + SRC_NB( srcGrid )
- SRC_ST( srcGrid ) - SRC_SB( srcGrid );
uy /= rho;
}
else
uy = 0.002;
if( TEST_FLAG_SWEEP( srcGrid, ACCEL )) {
uz = + SRC_T ( srcGrid ) - SRC_B ( srcGrid )
+ SRC_NT( srcGrid ) - SRC_NB( srcGrid )
+ SRC_ST( srcGrid ) - SRC_SB( srcGrid )
+ SRC_ET( srcGrid ) - SRC_EB( srcGrid )
+ SRC_WT( srcGrid ) - SRC_WB( srcGrid );
uz /= rho;
}
else
uz = 0.000;
Note that following floating point expressions are dependence chain containing 10 floating instructions
uz = + SRC_T ( srcGrid ) - SRC_B ( srcGrid )
+ SRC_NT( srcGrid ) - SRC_NB( srcGrid )
+ SRC_ST( srcGrid ) - SRC_SB( srcGrid )
+ SRC_ET( srcGrid ) - SRC_EB( srcGrid )
+ SRC_WT( srcGrid ) - SRC_WB( srcGrid );
uz /= rho;
One power8 each fp instruction has 6 or more cycle latency, so it needs at least 60 cycles to execute each of the three dependence chain.
GCC doesn't do the control flow transform, so it can interleave the 3 dependence chains, and the result code is much faster.
Perf run using options -m64 -O3 -fexperimental-new-pass-manager shows a 6% increase in 470.lbm with the new branch coalescing pass.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311588
Machine sinking is transforming the code as described above. I have verified that if I disable machine sinking, the performance is identical to GCC.
I will continue to investigate why machine sinking is doing this.