4

I am compiling some binaries for an ARMv8 and ARMv7 devices and I want to disable the branch predication. I know this question has been asked once (here) but the target was an x86 machine. I'm using a linaro gcc for arm.

I'm doing this for experiment sake and I don't recommend this as a practice.

I have used perf to measure branch instructions / branch misses count.

So I have 2 questions:

  1. Is branch predication utilised gcc/g++ for arm?
  2. How can I disable it?

I have tried the following options:

  • fno-branch-target-load-optimize(2) - No effect on the binary size but generated different assembly. However the branch statistics are identical as without using the option.
  • -fno-if-conversion(2) - Binary size identical, assembly different. This increased the number of branches being executed and also the branch miss rate. It appears that the option dose something.
  • -fno-guess-branch-probability - Same as above but it had lower impact.

So can I be sure that using -fno-if-conversion and -fno-guess-branch-probability are completely disabling branch predication?

Community
  • 1
  • 1
VAndrei
  • 5,420
  • 18
  • 43
  • The wikipedia page you link to says that aarch64 does not support branch predication. – Marc Glisse May 14 '15 at 09:45
  • Wow ... how come I've missed that. I need to check that. Still, the question remains. Is it possible to turn off predication. – VAndrei May 14 '15 at 09:54
  • somehow related https://gcc.gnu.org/ml/gcc/2008-02/msg00601.html Didn't read through the whole conversation but it seems they are talking like turning off branch predication is not an option. – bolov May 14 '15 at 10:00
  • The word is *prediction.* 'Predication' means something else entirely. – user207421 May 14 '15 at 10:06
  • 5
    @EJP: yes, predication and prediction are indeed different words. OP seems entirely aware of this and correctly used the word *predication* in her question. Which your edit has materially changed. – High Performance Mark May 14 '15 at 10:08
  • 1
    @EJP. I'm interested in "predication", not "prediction". I have made the edits back to reflect my intention. – VAndrei May 14 '15 at 10:11
  • 1
    Actually, if you disable it, instructions like `bne`, `bgt` are disabled altogether, which basically leaves you nothing to do even a conditional jump. And @MarcGlisse it's not entirely true that arm64 doesn't support branch predication, it just doesn't support fully conditional execution on all instructions. Using CMOV itself is sufficient to implement branch predication in most cases, although maybe less efficiently. – user3528438 May 14 '15 at 13:30
  • @user3528438 I'm nut sure I completely understand. If you remove bne and bgt basically you will execute both targets (if and else) so that will change program output. You need to have at lease some conditional instructions. Can you please elaborate on this? – VAndrei May 14 '15 at 13:44
  • @VAndrei That's why you simply can not do it. – user3528438 May 14 '15 at 13:54

1 Answers1

1

After doing more research and tests I have my answer.

In ARMv7 ISA there are predicated instructions. The compiler uses them when it thinks they are beneficial. This can be disabled with -fno-if-conversion -fno-if-conversion2 compilation flags. In cases where the branch predictor does a good job, this can potentially increase performance.

ARMv8 AArch64 ISA has very limited support for branch predication so basically there-s not much to disable. The number of predicated instructions is reduced at minimum. Even when using the -fno-if-conversion flags I don-t see any impact on the number of executed instructions (used perf for this). This means that the branch predictor is even more important.

VAndrei
  • 5,420
  • 18
  • 43