[LLVMbugs] [Bug 5652] New: Collapsing two comparisons not performed

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Mon Nov 30 19:01:13 PST 2009


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

           Summary: Collapsing two comparisons not performed
           Product: new-bugs
           Version: 2.6
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: bugzilla at isomer.meta.net.nz
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=3898)
 --> (http://llvm.org/bugs/attachment.cgi?id=3898)
Example showing missed optimisation opportunity.

(I'm not sure how to summarise this properly, someone please provide a better
summary?)

I have a program which basically boils down to in pseudo-C (my program calls
LLVM to generate the Module directly, so at no point is it actually in C, this
is for illustrative purposes only)

unsigned int bpf_run(unsigned char *packet, unsigned int length)
{
  if (length < 13 && *(unsigned short*)(&packet[12]) == 0x8035 && length < 21
&& *(unsigned short *)(&packet[20]) == 6) {
    return 42;
  } else {
    return 0;
  }
}

I'd expect LLVM to collapse the two length comparisons into one that's
performed first such as:

unsigned int bpf_run(unsigned char *packet, unsigned int length)
{
  if (length < 21 && *(unsigned short*)(&packet[12]) == 0x8035 && (unsigned
short *)(&packet[20]) == 6) {
    return 42;
  } else {
    return 0;
  }
}

However LLVM does not notice this potential optimisation, and believes the
first form is the most optimal.  This appears to be an important optimisation
for when people are guarding all array accesses with length checks (such as
this case).

Attached is a copy of the output of the optimiser, note that the "bpf_isn_2"
basic block should be collapsed into "entry" basic block.


-- 
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