Skip to content

Missed optimisation from flags on SUB #6146

@llvmbot

Description

@llvmbot
Bugzilla Link 5774
Version trunk
OS MacOS X
Reporter LLVM Bugzilla Contributor
CC @asl

Extended Description

Consider the following test case:

define i32 @foo1 ( i32 %a, i32 %b ) nounwind
{
entry:
	%sub = sub i32 %a, %b
	%diff = icmp slt i32 %a, %b
	%select = select i1 %diff, i32 %b, i32 %a
	%call = call i32 @bar ( i32 %sub, i32 %select )
	ret i32 %call
}

define i32 @foo2 ( i32 %a, i32 %b ) nounwind
{
entry:
	%sub = sub i32 %a, %b
	%diff = icmp slt i32 %sub, 0
	%select = select i1 %diff, i32 %b, i32 %a
	%call = call i32 @bar ( i32 %sub, i32 %select )
	ret i32 %call
}

declare i32 @bar ( i32 %a, i32 %b ) nounwind

Whilst the effect of both foo1 and foo2 are equivalent, foo2 uses the negative flag from the result of the sub for the condition; foo1 instead generates an extra compare instruction (on X86).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions