title: Is if else faster than if + default?
body: <p>I conducted a simple experiment, to compare if-else to only an if (with default values preset). Example:</p>
  
  <pre><code>void test0(char c, int *x) {
      *x = 0;
      if (c == 99) {
          *x = 15;
      }
  }
  
  void test1(char c, int *x) {
      if (c == 99) {
          *x = 15;
      } else {
          *x = 0;
      }
  }
  </code></pre>
  
  <p>For the functions above, I got the exact same assembly code (using <code>cmovne</code>).</p>
  
  <p>However when adding an extra variable:</p>
  
  <pre><code>void test2(char c, int *x, int *y) {
      *x = 0;
      *y = 0;
      if (c == 99) {
          *x = 15;
          *y = 21;
      }
  }
  
  void test3(char c, int *x, int *y) {
      if (c == 99) {
          *x = 15;
          *y = 21;
      } else {
          *x = 0;
          *y = 0;
      }
  }
  </code></pre>
  
  <p>The assembly suddenly becomes different:</p>
  
  <pre><code>test2(char, int*, int*):
          cmp     dil, 99
          mov     DWORD PTR [rsi], 0
          mov     DWORD PTR [rdx], 0
          je      .L10
          rep ret
  .L10:
          mov     DWORD PTR [rsi], 15
          mov     DWORD PTR [rdx], 21
          ret
  test3(char, int*, int*):
          cmp     dil, 99
          je      .L14
          mov     DWORD PTR [rsi], 0
          mov     DWORD PTR [rdx], 0
          ret
  .L14:
          mov     DWORD PTR [rsi], 15
          mov     DWORD PTR [rdx], 21
          ret
  </code></pre>
  
  <p>It seems that the only difference is if the top <code>mov</code>s are done before or after the <code>je</code>. </p>
  
  <p>Now (sorry my assembly is a bit crude), isn't it always better to have the <code>mov</code>s after the jump, in order to save pipeline flushes? And if so why wouldn't the optimizer (gcc6.2 -O3) use the better method?</p>