<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [AArch64] Poor codegen for BitfieldInsertOpFromOr when operands are commuted"
   href="http://llvm.org/bugs/show_bug.cgi?id=21631">21631</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[AArch64] Poor codegen for BitfieldInsertOpFromOr when operands are commuted
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: AArch64
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mcrosier@codeaurora.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>apazos@codeaurora.org, james.molloy@arm.com, llvmbugs@cs.uiuc.edu, t.p.northover@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>AFAICT, we can generate

        lsl     w8, w2, #16
        and     w0, w8, #0xff0000
        bfxil   w0, w1, #0, #16

as

        and     w0, w1, #0xffff
        bfi     w0, w2, #16, #8

removing the extra shift instruction.

Test cases:
$> more test.ll 
target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
target triple = "aarch64--linux-gnu"

define i32 @good(i32 %x, i32 %code, i32 %mode) {
entry:
  %bf.value = and i32 %code, 65535
  %bf.value2 = shl i32 %mode, 16
  %bf.shl = and i32 %bf.value2, 16711680
  %bf.set = or i32 %bf.shl, %bf.value
  ret i32 %bf.set
}

define i32 @bad(i32 %x, i32 %code, i32 %mode) {
entry:
  %bf.value = and i32 %code, 65535
  %bf.value2 = shl i32 %mode, 16
  %bf.shl = and i32 %bf.value2, 16711680
  %bf.set = or i32 %bf.value, %bf.shl
  ret i32 %bf.set
}

Reproduce:
$> llc -O3 test.ll -o -
        .text
        .file   "test.ll"
        .globl  good
        .align  2
        .type   good,@function
good:                                   // @good
        .cfi_startproc
// BB#0:                                // %entry
        and     w0, w1, #0xffff
        bfi     w0, w2, #16, #8
        ret
.Ltmp1:
        .size   good, .Ltmp1-good
        .cfi_endproc

        .globl  bad
        .align  2
        .type   bad,@function
bad:                                    // @bad
        .cfi_startproc
// BB#0:                                // %entry
        lsl     w8, w2, #16
        and     w0, w8, #0xff0000
        bfxil   w0, w1, #0, #16
        ret
.Ltmp3:
        .size   bad, .Ltmp3-bad
        .cfi_endproc</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>