Skip to content

Serious tail merging pessimization #2281

Closed
@lattner

Description

@lattner
Bugzilla Link 1909
Resolution FIXED
Resolved on Feb 26, 2008 13:55
Version 2.1
OS All

Extended Description

Consider:

#include <stdio.h>
#include <stdlib.h>

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
void minmax(float result[8]) {
float min_x, max_x, min_y, max_y;

min_x = MIN(result[0], MIN(result[2], MIN(result[4], result[6])));
max_x = MAX(result[0], MAX(result[2], MAX(result[4], result[6])));
min_y = MIN(result[1], MIN(result[3], MIN(result[5], result[7])));
max_y = MAX(result[1], MAX(result[3], MAX(result[5], result[7])));

printf("transformed bounds: (%.2f, %.2f), (%.2f, %.2f)\n", min_x, min_y, max_x, max_y);
}

Without tail merging, we get ugly code. With tail merging, we get aweful code :) It seems to be merging lots of "single instructions", yielding code like this:

LBB1_53: # bb
ucomiss %xmm3, %xmm1
jmp LBB1_2 # bb21
LBB1_54: # bb128
ucomiss %xmm1, %xmm3
jmp LBB1_15 # bb136
LBB1_55: # bb243
ucomiss %xmm3, %xmm1
jmp LBB1_28 # bb251
LBB1_56: # bb358
ucomiss %xmm1, %xmm3
jmp LBB1_41 # bb366
LBB1_57: # bb395
ucomiss %xmm0, %xmm2
jmp LBB1_44 # bb385
LBB1_58: # bb425.bb456_crit_edge
movl %edi, %eax
jmp LBB1_52 # bb456
...

at the end of the function. If this is what is happening, it should be fixed. Saving a single instruction isn't worthwhile because we have to add the jump, and this makes code potentially slower.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions