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.
Yep, this is because MachineCSE isn't doing everything it needs to
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.
r130928.