[llvm-bugs] [Bug 41554] New: Constant Hoist Makes Inconsistent Code Generation

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Apr 21 23:47:24 PDT 2019


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

            Bug ID: 41554
           Summary: Constant Hoist Makes Inconsistent Code Generation
           Product: new-bugs
           Version: 7.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: manjian2006 at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

#include <stdint.h>
struct MemChunk {
  int a, flags;
};
void SlowFoo(void* a, void* b);
static const int kPageSizeBits = 19;
static inline MemChunk* ToMemChunk(void* o) {
  uintptr_t i = reinterpret_cast<intptr_t>(o);
  const int page_mask = ~((1 << kPageSizeBits) - 1);
  i = i & page_mask;
  return reinterpret_cast<MemChunk*>(i);
}
void foo(void* a, void* b) {
  MemChunk* m_a = ToMemChunk(a);
  if ((m_a->flags & 2) == 0)
    return;
  MemChunk* m_b = ToMemChunk(b);
  if ((m_b->flags & 2) == 0)
    return;
  SlowFoo(a, b);
}

compiles with -target armv7-linux-androideabi -fPIC  -O3 -mllvm -debug   -S   
-march=armv7-a -mfloat-abi=softfp -mfpu=neon -marm  
--sysroot=/home/linzj/android-ndk-r13b/platforms/android-15/arch-arm/
--gcc-toolchain=/home/linzj/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/
-fomit-frame-pointer -fvisibility=hidden

And gen

    mov r2, #4
    mov r3, r0
    bfi r3, r2, #0, #19
    ldrb    r2, [r3]
    tst r2, #2
    bxeq    lr
    movw    r2, #0
    movt    r2, #65528
    and r2, r1, r2
    ldrb    r2, [r2, #4]
    tst r2, #2
    bne .LBB0_2
@ %bb.1:
    bx  lr
.LBB0_2:
    b   _Z7SlowFooPvS_

note that the first and is combined as bfi instruction, but the second one
would not.
I think
        mov     r2, #4
        mov     r3, r0
        bfi     r3, r2, #0, #19
        ldrb    r3, [r3]
        tst     r3, #2
        bxeq    lr
        mov     r3, r1
        bfi     r3, r2, #0, #19
        ldrb    r2, [r3]
        tst     r2, #2
        bne     .LBB0_2
@ %bb.1:                                @ %cleanup7
        bx      lr
.LBB0_2:                                @ %if.end6
        b       _Z7SlowFooPvS_

is better output.

-- 
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/20190422/b6549717/attachment.html>


More information about the llvm-bugs mailing list