http://llvm.org/bugs/show_bug.cgi?id=21631

            Bug ID: 21631
           Summary: [AArch64] Poor codegen for BitfieldInsertOpFromOr when
                    operands are commuted
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: AArch64
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]
    Classification: Unclassified

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to