[LLVMbugs] [Bug 6627] New: llvm doesn't merge adjacent cmps

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Mar 16 06:07:30 PDT 2010


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

           Summary: llvm doesn't merge adjacent cmps
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Keywords: code-quality
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: benny.kra at gmail.com
                CC: llvmbugs at cs.uiuc.edu, rdivacky at freebsd.org


Test case (by rdivacky):
===

typedef unsigned int uint32_t;
typedef struct {
    unsigned char e_ident[16];
} Elf32_Ehdr;

struct exec {
     uint32_t a_midmag;
     uint32_t a_text;
     uint32_t a_data;
     uint32_t a_bss;
     uint32_t a_syms;
     uint32_t a_entry;
     uint32_t a_trsize;
     uint32_t a_drsize;
};


foo() {
    union {
 struct exec ex;
 Elf32_Ehdr eh;
    } hdr;


   bar(&hdr);    // pretend to fill something in

   // $CC -std=c99 -Os -S stack-compare.c
   // 
   // clang:
   //
   //     callq   bar
   //     cmpb    $127, -32(%rbp)
   //     jne     .LBB1_5
   //     cmpb    $69, -31(%rbp)
   //     jne     .LBB1_5
   //     cmpb    $76, -30(%rbp)
   //     jne     .LBB1_5
   //     cmpb    $70, -29(%rbp)
   //     jne     .LBB1_5
   //     xorb    %al, %al
   //     callq   doo
   //
   // gcc:
   //        call    bar
   //        cmpl    $1179403647, (%esp)
   //        jne     .L5
   //
   // ie. gcc can combine all these into one compare while llvm cant

   if (((hdr.eh).e_ident[0] == 0x7f && (hdr.eh).e_ident[1] == 'E' &&
(hdr.eh).e_ident[2] == 'L' && (hdr.eh).e_ident[3] == 'F')) {
      doo();
   }

}

===
GCC does this transformation because it sees the uint32_t through the union. I
think it could be safely applied to any cmp with a fixed-size stack allocated
array though (GCC doesn't do this).

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list