LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 8361 - duplicated compare instruction
Summary: duplicated compare instruction
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: X86 (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks: 8125
  Show dependency tree
 
Reported: 2010-10-12 08:22 PDT by Edmund Grimley Evans
Modified: 2011-05-05 12:04 PDT (History)
6 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Edmund Grimley Evans 2010-10-12 08:22:36 PDT
Keywords: duplicate duplicated redundant repeated compare comparison cmp

The compare instruction is repeated unnecessarily in the code generated from this:

const char *f(int x, int y)
{
  return x < y ? "<" : x == y ? "=" : ">";
}

I've seen this with the ARM and x86 back ends.

Currently on r116298.
Comment 1 Chris Lattner 2010-10-12 11:20:44 PDT
Yep, this is because MachineCSE isn't doing everything it needs to
Comment 2 Gabor Greif 2010-10-12 16:31:05 PDT
This problem shows up on all targets I look at:

PPC32:
f:                                      # @f
# BB#0:                                 # %entry
        cmpw 0, 3, 4
        blt 0, .LBB0_4
# BB#1:                                 # %cond.false
        cmplw 0, 3, 4
        bne 0, .LBB0_3


Thumb:
f:
@ BB#0:                                 @ %entry
        cmp     r0, r1
        blt     .LBB0_4
@ BB#1:                                 @ %cond.false
        cmp     r0, r1
        bne     .LBB0_3


ARM:
f:                                      @ @f
@ BB#0:                                 @ %entry
        cmp     r0, r1
        ldrlt   r0, .LCPI0_2
        bxlt    lr
        ldr     r3, .LCPI0_1
        cmp     r0, r1
        mov     r0, r3


x86:
f:                                      # @f
# BB#0:                                 # %entry
        movl    8(%esp), %eax
        movl    4(%esp), %ecx
        cmpl    %eax, %ecx
        jl      .LBB0_2
# BB#1:                                 # %cond.false
        cmpl    %eax, %ecx
        movl    $.L.str1, %ecx


Starting investigation, maybe I can come up with something acceptable.
Comment 3 Eli Friedman 2011-05-05 12:04:32 PDT
r130928.