Skip to content

suboptimal code generation in loop unrolling #11568

@llvmbot

Description

@llvmbot
Bugzilla Link 11196
Version trunk
OS All
Attachments test case
Reporter LLVM Bugzilla Contributor
CC @atrick,@nlewycky

Extended Description

I attached a llvm-ir translation of the following program:
static init
begin
if(copy('hello', 1, 2) == 'el') {
log('correct')
}
end

This program should be completely constant folded, but the optimization stucks at a loop:
the loop begins at line 51 and compares two strings of the same size.
As you see in line 61+63 and 62+64, the characters of the strings at this specific position are loaded and this exactly is the problem.

It is about the same issue like http://llvm.org/bugs/show_bug.cgi?id=11142
but this time, it's a bit more complex: the memory is not directly copied, but it's received by a getelementptr+load from the malloced memory.
The challenge is to proof that the loop will stay exactly in the copied range of [3 x i8]* @​label416 so that the getelementptr call can fetched from @​label416 instead of %result.i.i10

An other question is why the loop that only consists of two iterations is not constant folded.
The loop has the following structure:

start:
br label %test
test:
%loopvar = phi i32 [%loopvar2, %body], [0, %start]
%finished = icmp sgt i32 %loopvar, 2 ; or any other constant or non-constant
br i1 %finished, label %continue, label %body
body:
; sth fancy
%otherbreak = icmp .....
br i1 %otherbreak, label %exception, label %test
continue:

This report is maybe two bugs but when you fix one of the two issues, the test case will become unusable to test the other issue because of constant folding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions