[llvm-bugs] [Bug 34526] New: Improve bitfield arithmetic

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 8 04:38:21 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=34526

            Bug ID: 34526
           Summary: Improve bitfield arithmetic
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: llvm-dev at redking.me.uk
                CC: llvm-bugs at lists.llvm.org, spatel+llvm at rotateright.com

We could improve math ops on irregular bitfields with the relevant SWAR style
patterns:

struct Counters {
  unsigned a:7;
  unsigned b:16;
  unsigned c:9;
};

Counters IncCounters(Counters x) {
  x.a++;
  x.b++;
  x.c++;
  return x;
}

Counters AddCounters(Counters x, Counters y) {
  Counters c;
  c.a = x.a + y.a;
  c.b = x.b + y.b;
  c.c = x.c + y.c;
  return c;
}

define i32 @IncCounters(i32) {
  %2 = add i32 %0, 1
  %3 = and i32 %2, 127
  %4 = add i32 %0, 128
  %5 = and i32 %4, 8388480
  %6 = or i32 %5, %3
  %7 = add i32 %0, 8388608
  %8 = and i32 %7, -8388608
  %9 = or i32 %6, %8
  ret i32 %9
}

define i32 @AddCounters(i32, i32) {
  %3 = add i32 %1, %0
  %4 = and i32 %3, 127
  %5 = and i32 %0, 8388480
  %6 = add i32 %5, %1
  %7 = and i32 %6, 8388480
  %8 = or i32 %4, %7
  %9 = and i32 %0, -8388608
  %10 = add i32 %9, %1
  %11 = and i32 %10, -8388608
  %12 = or i32 %8, %11
  ret i32 %12
}

llc -mcpu=btver2

IncCounters(Counters): # @IncCounters(Counters)
  movl %edi, %ecx
  leal 1(%rdi), %eax
  addl $8388608, %edi # imm = 0x800000
  subl $-128, %ecx
  andl $127, %eax
  andl $-8388608, %edi # imm = 0xFF800000
  andl $8388480, %ecx # imm = 0x7FFF80
  orl %ecx, %eax
  orl %edi, %eax
  retq

AddCounters(Counters, Counters): # @AddCounters(Counters, Counters)
  movl %edi, %ecx
  leal (%rsi,%rdi), %eax
  andl $-8388608, %edi # imm = 0xFF800000
  andl $8388480, %ecx # imm = 0x7FFF80
  addl %esi, %edi
  andl $127, %eax
  addl %esi, %ecx
  andl $-8388608, %edi # imm = 0xFF800000
  andl $8388480, %ecx # imm = 0x7FFF80
  orl %ecx, %eax
  orl %edi, %eax
  retq

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170908/58a75f10/attachment.html>


More information about the llvm-bugs mailing list