Go to file
JF Bastien fa9746dc8d x86: Emit LAHF/SAHF instead of PUSHF/POPF
NaCl's sandbox doesn't allow PUSHF/POPF out of security concerns (priviledged emulators have forgotten to mask system bits in the past, and EFLAGS's DF bit is a constant source of hilarity). Commit r220529 fixed PR20376 by saving cmpxchg's flags result using EFLAGS, this commit now generated LAHF/SAHF instead, for all of x86 (not just NaCl) because it leads to an overall performance gain over PUSHF/POPF.

As with the previous patch this code generation is pretty bad because it occurs very later, after register allocation, and in many cases it rematerializes flags which were already available (e.g. already in a register through SETE). Fortunately it's somewhat rare that this code needs to fire.

I did [[ https://github.com/jfbastien/benchmark-x86-flags | a bit of benchmarking ]], the results on an Intel Haswell E5-2690 CPU at 2.9GHz are:

| Time per call (ms)  | Runtime (ms) | Benchmark                      |
| 0.000012514         |      6257    | sete.i386                      |
| 0.000012810         |      6405    | sete.i386-fast                 |
| 0.000010456         |      5228    | sete.x86-64                    |
| 0.000010496         |      5248    | sete.x86-64-fast               |
| 0.000012906         |      6453    | lahf-sahf.i386                 |
| 0.000013236         |      6618    | lahf-sahf.i386-fast            |
| 0.000010580         |      5290    | lahf-sahf.x86-64               |
| 0.000010304         |      5152    | lahf-sahf.x86-64-fast          |
| 0.000028056         |     14028    | pushf-popf.i386                |
| 0.000027160         |     13580    | pushf-popf.i386-fast           |
| 0.000023810         |     11905    | pushf-popf.x86-64              |
| 0.000026468         |     13234    | pushf-popf.x86-64-fast         |

Clearly `PUSHF`/`POPF` are suboptimal. It doesn't really seems to be worth teaching LLVM about individual flags, at least not for this purpose.

Reviewers: rnk, jvoung, t.p.northover

Subscribers: llvm-commits

Differential revision: http://reviews.llvm.org/D6629

llvm-svn: 244503
2015-08-10 20:59:36 +00:00
clang Fix test case to work with -Asserts builds. 2015-08-10 20:58:54 +00:00
clang-tools-extra misc-unused-parameters: Don't touch K&R style functions. 2015-08-10 15:45:46 +00:00
compiler-rt Fix typo. 2015-08-10 18:26:29 +00:00
debuginfo-tests New round of fixes for "Always compile debuginfo-tests for the host triple" 2014-10-18 23:47:59 +00:00
libclc Require LLVM >=3.7 and bump version to 0.2.0 2015-08-07 08:31:37 +00:00
libcxx Protect template argument from user interference. 2015-08-10 16:58:04 +00:00
libcxxabi Update to new lists.llvm.org 2015-08-05 04:01:26 +00:00
libunwind Revert test commit. 2015-08-06 23:31:37 +00:00
lld Add a test for our handling of shndx. 2015-08-10 18:28:24 +00:00
lldb Allow dosep.py to print dotest.py output on success. 2015-08-10 17:46:11 +00:00
llgo Update to new lists.llvm.org 2015-08-05 04:03:05 +00:00
llvm x86: Emit LAHF/SAHF instead of PUSHF/POPF 2015-08-10 20:59:36 +00:00
openmp Fix link error on Windows when LIBOMP_USE_DEBUGGER is off 2015-08-06 15:16:54 +00:00
polly Correct non-existing past participle of split in filename 2015-08-10 18:37:34 +00:00