[llvm-commits] [PATCH] optimization of max-like struct for x86

manman ren mren at apple.com
Mon Apr 30 12:06:24 PDT 2012


This patch optimizes codegen on X86 for the following cases:
(a > b) ? a-b : 0
(b < a) ? a-b : 0

The cmpl instruction is removed:
< 	xorl	%eax, %eax
< 	subl	%esi, %edi
< 	cmovll	%eax, %edi
< 	movl	%edi, %eax
---
> 	movl	%edi, %ecx
> 	subl	%esi, %ecx
> 	cmpl	%edi, %esi
> 	movl	$0, %eax
> 	cmovll	%ecx, %eax

Please review & provide feedback,
Thanks,
Manman

-------------- next part --------------
A non-text attachment was scrubbed...
Name: max_like.patch
Type: application/octet-stream
Size: 3604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120430/566fa407/attachment.obj>
-------------- next part --------------


On Apr 26, 2012, at 9:19 AM, Manman Ren wrote:

> 
> This can be beneficial to other architectures as well.
> The main idea is to remove the comparison (b > a) and use the result from sub (b-a).
> But first, I need to figure out how to use cmova instead of cmovs. Thanks Steve for pointing that out.
> I didn't see an ISD opcode which can be used to get the flags out of the sub SDNode.
> The other option is to implement this in Lowering, which is likely to be target dependent.
> 
> Thanks,
> Manman
> 
> On Apr 25, 2012, at 2:24 PM, Evan Cheng <evan.cheng at apple.com> wrote:
> 
>> Have you considered making this into a target independent dag combine?
>> 
>> Evan
>> 
>> On Apr 25, 2012, at 9:33 AM, Manman Ren <mren at apple.com> wrote:
>> 
>>> 
>>> This patch is intended to optimize the following cases for x86:
>>> (b > a) ? (b-a) : 0
>>> (a < b) ? (b-a) : 0
>>> It will use cmovs in generated x86 code.
>>> 
>>> The patch modified one source file: lib/Target/X86/X86ISelLowering.cpp
>>> 
>>> Please review & provide feedback.
>>> Thanks,
>>> 
>>> <opt_max_x86.patch>_______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>> 
> 



More information about the llvm-commits mailing list