[llvm] r190309 - [ARMv8] Prevent generation of deprecated IT blocks on ARMv8 in Thumb mode.

Artyom Skrobov Artyom.Skrobov at arm.com
Thu Nov 28 06:23:58 PST 2013

Hello Hal,

>>>> Hal, can you confirm that this patch restores the correct
>>>> functioning
>>>> on PPC?
>>> I'll check.
>>> Why are you restoring this part?
>>>      if (BBI.ClobbersPred && !isPredicated) {
>>>        // Predicate modification instruction should end the block
>>>        (except for
>>>        // already predicated instructions and end of block
>>>        branches).
>>> +      if (isCondBr) {
>>> +        // A conditional branch is not predicable, but it may be
>>> eliminated.
>>> +        continue;
>>> +      }
>>> +
>> This enables conversion of fragments such as
>>         cmp     r12, r2
>>         bne     .LBB6_4
>> @ BB#2:
>>         cmp     r1, r3
>>         bne     .LBB6_4
>>         strexd  r5, lr, r4, [r0]
>> into
>>         cmp     r12, r2
>>         it      eq
>>         cmpeq   r1, r3
>>         bne     .LBB6_4
>> @ BB#2:
>>         strexd  r5, lr, r4, [r0]
>> As you can see, in this case, the last instruction of the branch (cmp
>> r1, r3; bne .LBB6_4) is not predicable on the branch condition (the
>> original CPSR), but it's going to be eliminated during the
>> conversion, so its non-predicability doesn't matter.
> Can you explain what this means? I still obviously see those
> instructions in the transformation result.

I'll do my best.

The source construct here is of the form

        /  |
     BB2   |
    /   \  |
  BB3    BB4

--corresponding to if(cond1 && cond2) {BB3} else {BB4}

ScanInstructions() is called on BB2 to check if it can be predicated and merged into BB1.
Because of the clause with "if(isCondBr)", ScanInstructions() skips over the final branch instruction of BB2, and returns with IsUnpredicable=false, indicating that the conversion is possible.

This allows IfConverter::AnalyzeBlock() to recognize the construct as a valid ICTriangle, and IfConverter::IfConvertTriangle() is called to perform the actual IfConversion.
If you scroll the source of IfConverter::IfConvertTriangle() down, to the comment
"// Predicate the 'true' block after removing its branch.",
you will see the unpredicable final branch of BB2 getting removed, as well as the final branch of BB1.
Following this, the two BB's are merged, and a new branch to BB4 is created to terminate the merged BB.

If the clause with "if(isCondBr)" is removed, then none of this conversion is possible for the shown example.
Hope this explanation helps.

More information about the llvm-commits mailing list