[llvm-commits] [Patch] Optimize integer ABS on X86
evan.cheng at apple.com
Thu Jun 7 13:07:57 CDT 2012
On Jun 7, 2012, at 9:46 AM, Manman Ren wrote:
> Hi Evan,
> PerformXorCombine was enabled only when Subtarget has BMI.
> Since now I have to check Xor for abs pattern, I enabled it for all X86 Subtargets.
> First, we check whether it is abs, if it is, RV will not be NULL.
> We will continue optimizations for BMI if RV is NULL and Subtarget has BMI.
Ok, I would suggest something like this to make it more obvious.
SDValue RV = performIntegerAbsCombine(N, DAG);
// Try forming BMI if it's available.
> I will add more comments in the code.
> Thanks for reviewing.
> On Jun 6, 2012, at 6:15 PM, Evan Cheng wrote:
>> This part looks weird to me:
>> + SDValue RV = performIntegerAbsCombine(N, DAG);
>> + if (RV.getNode() || !Subtarget->hasBMI())
>> + return RV;
>> Why is the code returning RV if its Node is null just because Subtarget->hasBMI() is false? Should the subtarget feature check happen earlier? The rest of the patch looks fine to me. Please commit after you have fixed the hasBMI issue.
>> On Jun 6, 2012, at 4:01 PM, Manman Ren <mren at apple.com> wrote:
>>> Optimize generated code for integer ABS on X86:
>>> movl %edi, %ecx
>>> sarl $31, %ecx
>>> leal (%rdi,%rcx), %eax
>>> xorl %ecx, %eax
>>> movl %edi, %eax
>>> negl %eax
>>> cmovll %edi, %eax
>>> This reduces code size and has better performance on sandy bridge.
>>> There exists a target-independent DAG combine for integer ABS, which converts abs to sar+add+xor.
>>> For X86, I tried to match this pattern back to neg+cmov. This is implemented in PerformXorCombine.
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
More information about the llvm-commits