Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch lowering makes ugly code for a simple scanning loop #1336

Closed
lattner opened this issue Oct 22, 2006 · 3 comments
Closed

switch lowering makes ugly code for a simple scanning loop #1336

lattner opened this issue Oct 22, 2006 · 3 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla code-quality llvm:codegen

Comments

@lattner
Copy link
Collaborator

lattner commented Oct 22, 2006

Bugzilla Link 964
Resolution FIXED
Resolved on Feb 22, 2010 12:41
Version 1.8
OS All

Extended Description

Consider this function (very similar to strhr):

void foo(unsigned char C);
const char *FindChar(const char *CurPtr) {
unsigned char C;
do
C = *CurPtr++;
while (C != 'x' && C != '\0');

foo(C);
return CurPtr;
}

We currently compile the loop to:

LBB1_1: #bb
movb (%esi), %al
incl %esi
cmpb $119, %al
jg LBB1_4 #bb
LBB1_3: #bb
testb %al, %al
je LBB1_2 #bb7
jmp LBB1_1 #bb
LBB1_4: #bb
cmpb $120, %al
jne LBB1_1 #bb

It seems that switch lowering could produce something like:

    cmpb $120, %al
    je out
    testb %al, %al
    jnz LBB1_1       #bb7

which would be much faster.

-Chris

@lattner
Copy link
Collaborator Author

lattner commented Oct 22, 2006

assigned to @lattner

@lattner
Copy link
Collaborator Author

lattner commented Oct 22, 2006

GCC generates code very close to the desired code:

L3:
movzbl (%esi), %eax
addl $1, %esi
cmpb $120, %al
je L4
testb %al, %al
jne L3

@lattner
Copy link
Collaborator Author

lattner commented Oct 22, 2006

Implemented. Testcase here: Regression/CodeGen/Generic/SwitchLowering.ll

Patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20061016/038932.html

We now compile the inner loop to:

LBB1_1: #bb
movb (%esi), %al
incl %esi
testb %al, %al
je LBB1_2 #bb7
LBB1_3: #bb
cmpb $120, %al
jne LBB1_1 #bb

-Chris

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla code-quality llvm:codegen
Projects
None yet
Development

No branches or pull requests

1 participant