[llvm-dev] PHI node to different register class vs TailDuplication

Mikael Holmén via llvm-dev llvm-dev at lists.llvm.org
Sun Mar 6 23:29:51 PST 2016


Hi,

On 03/05/2016 01:36 AM, Matthias Braun via llvm-dev wrote:
> A PHI can be thought of - and will be lowered to - COPY instructions at the end of the respective predecessor blocks. So what you need in the example is that a COPY instruction from class "aNlh_0_7" to class "rN" is valid and that a COPY from class "aNlh_rN" to class "rN" is valid.

Both those COPY:s are valid.

However, TailDuplication doesn't insert any COPY, but just replaces the 
PHI dst uses with PHI src, and thus messes up the register classes.

You consider this a bug in TailDuplication then?

As I said, if I do the following in TailDuplicatePass::ProcessPHI and 
insert a COPY myself, then it seems to work for me:

    const TargetRegisterClass *RC = MRI->getRegClass(DefReg);
+  const TargetRegisterClass *SrcRC = MRI->getRegClass(SrcReg);
+
+  // If the register class of the PHI src is wider than the PHI def
+  // then we can't just use PHI src instead of PHI def in the cloned
+  // instruction. Instead we insert a copy, copying the PHI src to a
+  // register of the wanted register class.
+  if (!RC->hasSubClassEq(SrcRC)) {
+    unsigned NewDef = MRI->createVirtualRegister(RC);
+
+    BuildMI(*PredBB, PredBB->instr_end(), DebugLoc(),
+            TII->get(TargetOpcode::COPY), NewDef).addReg(SrcReg);
+    SrcReg = NewDef;
+  }
+

Thanks,
Mikael

>
> - Matthias
>
>> On Mar 4, 2016, at 11:09 AM, Krzysztof Parzyszek via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>>
>> On 3/4/2016 6:44 AM, Mikael Holmén via llvm-dev wrote:
>>>
>>> Is such a PHI node ok?
>>
>> That doesn't seem to be well documented. The PHI nodes are described as "representing an assignment", but what the "assignment" could be is not clear.  Even if there exists an instruction that could copy registers between register classes, if you cannot substitute the output operand with one of the input operands in any use of the output, the PHI would seem to be malformed.  At least, that is my interpretation.
>>
>> -Krzysztof
>>
>> --
>> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>



More information about the llvm-dev mailing list