[llvm-dev] How to avoid multiple registers definitions in customInserter.

Dominique Torette via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 10 01:43:52 PDT 2018


Hi,

I'm lowering some of the logical operators (by example the | operator)  on integer32.
Sadly my target only provide native instruction on high and low parts of 32 bits registers.
So, I have to generate a sequence of two native instructions (LOR followed by HOR).
I've introduced an Pseudo instruction with a custom inserter.

def OR_A_oo             : CLPPseudoInst<(ins FPUaOffsetOperand:$OffsetA,FPUaOffsetOperand:$OffsetB),(outs FPUaROUTADDRegisterClass:$FA_ROUTADD),
                                                                [], [RFLAGA],
                                                                "# OR_A_oo",
                                                                [(set FPUaROUTADDRegisterClass:$FA_ROUTADD,(or  FPUaOffsetOperand:$OffsetA,FPUaOffsetOperand:$OffsetB))],NoItinerary>
                                                                {let usesCustomInserter = 1;}

The instructions selection and registers allocation are performed with the pseudo.

        %4:fpuaoffsetclass = LOAD_A_r @a; FPUaOffsetClass:%4
        %5:fpuaoffsetclass = LOAD_A_r @b; FPUaOffsetClass:%5
        %6:fpuaroutaddregisterclass = OR_A_oo killed %5, killed %4, implicit-def dead %rflaga; FPUaROUTADDRegisterClass:%6 FPUaOffsetClass:%5,%4
        %7:fpuaoffsetclass = COPY %6; FPUaOffsetClass:%7 FPUaROUTADDRegisterClass:%6
        MOV_A_or killed %7, @c1; FPUaOffsetClass:%7
        %8:fpuaoffsetclass = LOAD_A_r @c1; FPUaOffsetClass:%8

A virtual register %6 has been allocated for the out of the pseudo. So far, so good.

My customInserter (see below) is may be over simplistic.
After investigation on the code produce by my customInserter, I've noticed the following problems:
        1)      %6 seems to be defined twice
        2)      %5 is killed twice.

320B            MOV_A_ro @a, def %4; FPUaOffsetClass:%4
336B            MOV_A_ro @b, def %5; FPUaOffsetClass:%5
352B            %6:fpuaroutaddregisterclass = LOR_A_oo killed %5, implicit-def %rflaga; FPUaROUTADDRegisterClass:%6 FPUaOffsetClass:%5
368B            %6:fpuaroutaddregisterclass = HOR_A_oo killed %5, implicit-def %rflaga; FPUaROUTADDRegisterClass:%6 FPUaOffsetClass:%5
384B            %7:fpuaoffsetclass = COPY %6; FPUaOffsetClass:%7 FPUaROUTADDRegisterClass:%6
400B            MOV_A_or killed %7, @c1; FPUaOffsetClass:%7
416B            MOV_A_ro @c1, def %8; FPUaOffsetClass:%8

Result: an assertion is raised... !!

********** PROCESS IMPLICIT DEFS **********
********** Function: _start
llc: /home/dte/eclipse-workspace/llvm/lib/CodeGen/MachineRegisterInfo.cpp:366: llvm::MachineInstr* llvm::MachineRegisterInfo::getVRegDef(unsigned int) const: Assertion `(I.atEnd() || std::next(I) == def_instr_end()) && "getVRegDef assumes a single definition or no definition"' failed.
LLVMSymbolizer: error reading file: No such file or directory

Here is the inner part of my customInserter.
Are there any additional actions to perform during the customInserter.

MachineBasicBlock *
CLPTargetLowering::emitLOpcodeHOpcode(MachineInstr &MI,
        MachineBasicBlock *MBB,
                  unsigned LOpcode,
                  unsigned HOpcode) const {
        const TargetInstrInfo *TII = Subtarget->getInstrInfo();
        DebugLoc Loc = MI.getDebugLoc();

        const MachineOperand operand0 = MI.getOperand(0);
        const MachineOperand operand1 = MI.getOperand(1);

        BuildMI(*MBB, MI, Loc, TII->get(LOpcode))
        .add(operand0)
        .add(operand1);
        BuildMI(*MBB, MI, Loc, TII->get(HOpcode))
        .add(operand0)
        .add(operand1);

        MI.eraseFromParent();

        return MBB;
}

Dominique Torette
System Architect
Rue des Chasseurs Ardennais - Liège Science Park - B-4031 Angleur
Tel: +32 (0) 4 361 81 11 - Fax: +32 (0) 4 361 81 20
www.spacebel.be





 ------------------------------------------------------------------------------

E-MAIL DISCLAIMER

The present message may contain confidential and/or legally privileged information. If you are not the intended addressee and in case of a transmission error, please notify the sender immediately and destroy this E-mail. Disclosure, reproduction or distribution of this document and its possible attachments is strictly forbidden.

SPACEBEL denies all liability for incomplete, improper, inaccurate, intercepted, (partly) destroyed, lost and/or belated transmission of the current information given that unencrypted electronic transmission cannot currently be guaranteed to be secure or error free.
Upon request or in conformity with formal, contractual agreements, an originally signed hard copy will be sent to you to confirm the information contained in this E-mail.

SPACEBEL denies all liability where E-mail is used for private use.

SPACEBEL cannot be held responsible for possible viruses that might corrupt this message and/or your computer system.
 -------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180910/9ee1adef/attachment.html>


More information about the llvm-dev mailing list