[PATCH] Check Dest Register Liveness using MRI in CondOpt pass

Gerolf Hoflehner ghoflehner at apple.com
Wed Jun 17 18:53:41 PDT 2015


In cases like this the question comes down to is the change the ‘right thing to do’, and it seems the answer in this case is yes. 

The branch folding optimization in ConditionalCompares can lengthen a critical path due to the extra compare and by changing branch prediction behavior (eg. combining a well predicted with and mispredicted branch can transform a well-predictable into a mis-predicted branch). But it can also help by shortening the critical path and improving branch predictability. As far as I can tell the heuristics of that optimization relies on magic constants (something like threshold = X*3/4)  and ignores branch behavior entirely. For this either dynamic profile data or 'heuristics like branches to error functions are rare’ need to be employed. So the commit in question simply flipped the behavior of a hit or miss “optimization”, and therefore that optimization needs to be rewritten or at least retuned.

For Zhaoshi’s question about MTR I suspected it might use LIs for depth/height computations. Taking a quick look there is one code line that checks for the isDead attribute. I think that should be changed along the line Pete had suggested for the "CondOpt pass” when he submitted his patch.

-Gerolf



> On Jun 4, 2015, at 10:32 AM, Zhaoshi <zhaoshiz at codeaurora.org> wrote:
> 
> I agree with Matthias that the Dead flags should be present and correct.
>  
> The question is why MachineTraceMetrices is implicitly relying on LiveIntervals.
>  
> We can leave the patch as-is for now while we investigate the above question. We can also make AArch64ConditionalCompares requires LI if no one has time/interest in finding the answer.
>  
> - Zhaoshi
>  
> From: llvm-commits-bounces at cs.uiuc.edu <mailto:llvm-commits-bounces at cs.uiuc.edu> [mailto:llvm-commits-bounces at cs.uiuc.edu <mailto:llvm-commits-bounces at cs.uiuc.edu>] On Behalf Of Matthias Braun
> Sent: Tuesday, June 02, 2015 15:26
> To: Pete Cooper
> Cc: llvm-commits; yi jiang
> Subject: Re: [PATCH] Check Dest Register Liveness using MRI in CondOpt pass
>  
> On a side note: If a register has no uses then all defs of it must be dead, but you can have multiple definitions and uses and still some of the register definitions can be dead. On the other hand I think the Dead flags on virtual registers are mandatory to be present and correct, this is independent of live intervals being available or not.
>  
> - Matthias
>  
>> On Jun 2, 2015, at 1:23 PM, Pete Cooper <peter_cooper at apple.com <mailto:peter_cooper at apple.com>> wrote:
>>  
>> Hi all
>>  
>> We’ve discovered that this change (which was meant to be a compile-time improvement only and so NFC) is changing behavior.  I’d like to get an idea of how you would all like to proceed.
>>  
>> So the behavioral difference isn’t in CondOpt, but the next pass called AArch64ConditionalCompares.  CondOpt ran first, but AArch64ConditionalCompares was also implicitly using the results of LiveInternvals via MachineTraceMetrics.
>>  
>> On bzip2 decompress, this patch has resulted in AArch64ConditionalCompares *not* performing a transformation because the metrics suggest its not profitable.  This results in performance improving almost 6% on that benchmark.
>>  
>> The specific difference in performance is the branch on line 871 of AArch64ConditionalCompares.  Prior to this patch the ResDepth and HeadDepth would be such that its profitable to do the work.  After the change, that branch finds its not profitable.  Looking in to where we get the data for that branch, MachineTraceMetrics is returning different depths due to the presence of kill/dead flags.
>>  
>> The worrying thing here is that MachineTraceMetrics is implicitly relying on LiveIntervals.  It doesn’t need it, but it silently giving different results before/after LI runs isn’t ideal.  I don’t know whether to document that, or say its a bug or not.
>>  
>> I can think of a few solutions, comments welcome on where to go from here.
>>  
>> 1 - Just revert this patch, it wasn’t NFC as it was meant to be.
>> 2 - Make AArch64ConditionalCompares require LiveIntervals.  This is an incremental improvement over what we had before as we’ve at least removed one pass being dependent on LI.
>> 3 - Teach MachineTraceMetrics to use MRI as this patch did for CondOpt. This will only work for virtual register dead def checks, so may not be suitable given physical register dead defs and kill flags will still differ depending on LI.
>> 4 - Leave things as they are as we actually have a performance improvement, and file a PR to try work out why AArch64ConditionalCompares can actually slow things down, i.e., reevaluate its heuristics in light of this data.
>>  
>> BTW, i’ve CCed Gerolf, Yi, and Michael who all did most of the work discovering the change here.  They and I are happy to help work out whats going on an how to proceed.  We can try provide more data, debug dumps, and IR if needed.
>>  
>> Thanks,
>> Pete
>>> On Apr 22, 2015, at 11:08 AM, Pete Cooper <peter_cooper at apple.com <mailto:peter_cooper at apple.com>> wrote:
>>>  
>>> Thanks Chad and Zhaoshi.
>>>  
>>> r235532.
>>>  
>>> Thanks,
>>> Pete
>>>> On Apr 22, 2015, at 11:02 AM, Chad Rosier <mcrosier at codeaurora.org <mailto:mcrosier at codeaurora.org>> wrote:
>>>>  
>>>> Zhaoshi gave your patch a LGTM.  Go for it.  Thanks, Pete.
>>>>  
>>>> From: Pete Cooper [mailto:peter_cooper at apple.com <mailto:peter_cooper at apple.com>] 
>>>> Sent: Wednesday, April 22, 2015 1:04 PM
>>>> To: mcrosier at codeaurora.org <mailto:mcrosier at codeaurora.org>
>>>> Cc: zhaoshiz at codeaurora.org <mailto:zhaoshiz at codeaurora.org>; apazos at codeaurora.org <mailto:apazos at codeaurora.org>; Tim Northover; Jiangning Liu; sdmitrouk at accesssoftek.com <mailto:sdmitrouk at accesssoftek.com>; llvm-commits
>>>> Subject: Re: [PATCH] Check Dest Register Liveness using MRI in CondOpt pass
>>>>  
>>>>  
>>>>> On Apr 22, 2015, at 8:04 AM, Chad Rosier <mcrosier at codeaurora.org <mailto:mcrosier at codeaurora.org>> wrote:
>>>>>  
>>>>> Pete,
>>>>> I’ve pinged Zhaoshi and Ana using our internal emails.  Hopefully, they can provide some feedback shortly.
>>>> Thanks Chad.  Sounds good.
>>>>  
>>>> Pete
>>>> 
>>>> 
>>>>>  
>>>>> Chad
>>>>>  
>>>>> From: Pete Cooper [mailto:peter_cooper at apple.com <mailto:peter_cooper at apple.com>] 
>>>>> Sent: Tuesday, April 21, 2015 6:51 PM
>>>>> To: mcrosier at codeaurora.org <mailto:mcrosier at codeaurora.org>
>>>>> Cc: zhaoshiz at codeaurora.org <mailto:zhaoshiz at codeaurora.org>; apazos at codeaurora.org <mailto:apazos at codeaurora.org>; Tim Northover; Jiangning Liu; sdmitrouk at accesssoftek.com <mailto:sdmitrouk at accesssoftek.com>; llvm-commits
>>>>> Subject: [PATCH] Check Dest Register Liveness using MRI in CondOpt pass
>>>>>  
>>>>> Hi Chad
>>>>>  
>>>>> http://reviews.llvm.org/D6048 <https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D6048&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=MOz2OsIHlXX17Lrpk-BtwnYKseHBxXVQz_wND6pITU8&s=9B2R2lBWI5AMVkJIuTI3PIwEpEEGpjY-JnEQFmBAk-w&e=> (everyone CCed here was CCed on it) added register liveness checking to the CondOpt pass.  It does this with
>>>>>  
>>>>>> if (I->getOperand(0).isDead())
>>>>>  
>>>>> However, this requires that some kind of liveness has been run beforehand, so the pass had to require live intervals.  Looking at the pass manager dump, we then invalidated live intervals shortly after CondOpt because other passes don’t preserve it.
>>>>>  
>>>>> Attached is a patch which removes the dependency on LiveIntervals by checking if the def has any uses.  If it has no uses then it was going to be marked dead anyway, so this is equivalent to your original code.  I’ve verified that this passes ‘make check’ and specifically stepped through the examples in combine-comparisons-by-cse.ll in lldb to ensure the behavior was the same.
>>>>>  
>>>>> When building a bitcode containing all of llc with/without this change, it results in one less run of LiveIntervals per MF and saves 4s out of 80s total compile time.
>>>>>  
>>>>> Thanks,
>>>>> Pete
>>> 
>>>  
>> 
>>  
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu <mailto:llvm-commits at cs.uiuc.edu>
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits <http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits>
>  
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu <mailto:llvm-commits at cs.uiuc.edu>
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits <http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150617/0aca6420/attachment.html>


More information about the llvm-commits mailing list