<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div style="margin:0;">Hi, </div><div style="margin:0;"><br></div><div style="margin:0;">I am trying to support addition of int64 on my target which has only 32 bit registers.</div><div style="margin:0;">The target has only normal add instruction which adds two 32 bit register, writes result to a register, and updates carry flag in flag regitser.</div><div style="margin:0;">It does not have the addwithcarry instruction which adds two register and carry flag, writes result to a register, and updates carry flag.</div><div style="margin:0;"><br></div><div style="margin:0;">I have refered to the implementation of 64bit addition on cortex-a7 which is arm architecture and have some questions.</div><div style="margin:0;">the c source, .ll file, and debug dump is attached.</div><div style="margin:0;">-----------------------------------------debug dump-------------------------------------------------------------</div><div style="margin:0;"><div style="margin:0;">1522Optimized legalized selection DAG: %bb.0 'foo:entry'</div><div style="margin:0;">1523SelectionDAG has 16 nodes:</div><div style="margin:0;">1524  t0: ch = EntryToken</div><div style="margin:0;">1525  t17: ch,glue = CopyToReg t0, Register:i32 $r0, t29</div><div style="margin:0;">1526      t8: i32,ch = CopyFromReg t0, Register:i32 %3</div><div style="margin:0;">1527      t4: i32,ch = CopyFromReg t0, Register:i32 %1</div><div style="margin:0;">1528    t25: i32,i32 = ARMISD::ADDE t8, t4, t29:1</div><div style="margin:0;">1529  t19: ch,glue = CopyToReg t17, Register:i32 $r1, t25, t17:1</div><div style="margin:0;">1530    t6: i32,ch = CopyFromReg t0, Register:i32 %2</div><div style="margin:0;">1531    t2: i32,ch = CopyFromReg t0, Register:i32 %0</div><div style="margin:0;">1532  t29: i32,i32 = ARMISD::ADDC t6, t2</div><div style="margin:0;">1533  t20: ch = ARMISD::RET_FLAG t19, Register:i32 $r0, Register:i32 $r1, t19:1</div><div style="margin:0;">---------------------------------------------------------------------------------------------------------------------</div><div style="margin:0;">Question 1:  </div><div style="margin:0;">In the lowering process, arm cortex-a7 simulate the carry flag by considering it as data dependence, such as t25: i32,i32 = ARMISD::ADDE t8, t4, t29:1. </div><div style="margin:0;">Is it safer by simulate the carry flag by using a MVT::Glue? </div><div style="margin:0;">If the DAG graph is large and we see it as data dependence,  is it possible that an other instruction is inserted between the two nodes/instructions, which have carry flag dependence, after emitting schedule in CodeGenAndEmitDAG()(SelectionDAGISel.cpp)?</div><div style="margin:0;">If the inserted instruction happens to update the carry flag, the second ARMISD::ADDE will have incorrect result. Or is it guaranteed  the case will not happen?</div><div style="margin:0;">------------------------------------debug dump-----------------------------------------------------------------</div><div style="margin:0;"><div style="margin:0;">1548ISEL: Starting selection on root node: t25: i32,i32 = ARMISD::ADDE t8, t4, t29:1</div><div style="margin:0;">1549ISEL: Starting pattern match</div><div style="margin:0;">1550  Initial Opcode index to 94735</div><div style="margin:0;">1551  Match failed at index 94748</div><div style="margin:0;">1552  Continuing at 94777</div><div style="margin:0;">1553  Match failed at index 94778</div><div style="margin:0;">1554  Continuing at 94806</div><div style="margin:0;">1555  Continuing at 94807</div><div style="margin:0;">1556  Match failed at index 94808</div><div style="margin:0;">1557  Continuing at 94838</div><div style="margin:0;">1558  Continuing at 94839</div><div style="margin:0;">1559  Match failed at index 94842</div><div style="margin:0;">1560  Continuing at 95134</div><div style="margin:0;">1561Creating new node: t35: ch,glue = CopyToReg t0, Register:i32 $cpsr, t29:1</div><div style="margin:0;">1562  Morphed node: t25: i32,i32 = ADCrr t8, t4, TargetConstant:i32<14>, Register:i32 $noreg, Register:i32 $noreg, t35:1</div><div style="margin:0;">1563ISEL: Match complete!</div><div style="margin:0;">----------------------------------td file(ARMInstrInfo.td)-------------------------------------------------------------------------------</div><div style="margin:0;"><div style="margin:0;">3717let isAdd = 1 in</div><div style="margin:0;">3718defm ADC : AI1_adde_sube_irs<0b0101, "adc", ARMadde, 1>;</div><div><br></div><div><div>1740/// AI1_adde_sube_irs - Define instructions and patterns for adde and sube.</div><div>1741let TwoOperandAliasConstraint = "$Rn = $Rd" in</div><div>1742multiclass AI1_adde_sube_irs<bits<4> opcod, string opc, SDNode opnode,</div><div>1743                             bit Commutable = 0> {</div><div>1744  let hasPostISelHook = 1, Defs = [CPSR], Uses = [CPSR] in {</div><div>1745  def ri : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, mod_imm:$imm),</div><div>1746                DPFrm, IIC_iALUi, opc, "\t$Rd, $Rn, $imm",</div><div>1747               [(set GPR:$Rd, CPSR, (opnode GPR:$Rn, mod_imm:$imm, CPSR))]>,</div><div>1748               Requires<[IsARM]>,</div><div>1749           Sched<[WriteALU, ReadALU]> {</div><div>1750    bits<4> Rd;</div><div>1751    bits<4> Rn;</div><div>1752    bits<12> imm;</div><div>1753    let Inst{25} = 1;</div><div>1754    let Inst{15-12} = Rd;</div><div>1755    let Inst{19-16} = Rn;</div><div>1756    let Inst{11-0} = imm;</div><div>1757  }</div><div>1758  def rr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),</div><div>1759                DPFrm, IIC_iALUr, opc, "\t$Rd, $Rn, $Rm",</div><div>1760               [(set GPR:$Rd, CPSR, (opnode GPR:$Rn, GPR:$Rm, CPSR))]>,</div><div>1761               Requires<[IsARM]>,</div><div>1762           Sched<[WriteALU, ReadALU, ReadALU]> {</div><div>1763    bits<4> Rd;</div><div>1764    bits<4> Rn;</div><div>1765    bits<4> Rm;</div><div>1766    let Inst{11-4} = 0b00000000;</div><div>1767    let Inst{25} = 0;</div><div>1768    let isCommutable = Commutable;</div><div>1769    let Inst{3-0} = Rm;</div><div>1770    let Inst{15-12} = Rd;</div><div>1771    let Inst{19-16} = Rn;</div><div>1772  }</div></div><div>-------------------------------------------------------------------------------------------------------------------------------------------</div><div>Question 2:</div><div>When selecting ARMISD::ADDE, a new node(t35) is created. Why does tablegen create a new node?</div><div>Is this behavior related with the code "(opnode GPR:$Rn, GPR:$Rm, CPSR))" at line 1760?</div><div>Is it because CPSR is a parameter of opnode? </div><div><br></div><div>---------------------------------------------debug dump------------------------------------------------------------------------------</div><div><div>1812Total amount of phi nodes to update: 0</div><div>1813*** MachineFunction at end of ISel ***</div><div>1814# Machine code for function foo: IsSSA, TracksLiveness</div><div>1815Function Live Ins: $r0 in %0, $r1 in %1, $r2 in %2, $r3 in %3</div><div>1816</div><div>1817bb.0.entry:</div><div>1818  liveins: $r0, $r1, $r2, $r3</div><div>1819  %3:gpr = COPY $r3</div><div>1820  %2:gpr = COPY $r2</div><div>1821  %1:gpr = COPY $r1</div><div>1822  %0:gpr = COPY $r0</div><div>1823  %4:gpr = ADDrr %2:gpr, %0:gpr, 14, $noreg, def $cpsr</div><div>1824  %5:gpr = ADCrr %3:gpr, %1:gpr, 14, $noreg, $noreg, implicit $cpsr</div><div>1825  $r0 = COPY %4:gpr</div><div>1826  $r1 = COPY %5:gpr</div><div>1827  BX_RET 14, $noreg, implicit $r0, implicit $r1</div><div>1828</div><div>1829# End machine code for function foo.</div></div><div>-----------------------------------------------------------------------------------------------------------------------------------------------</div><div>Question 3:</div><div>if the basic block bb.0.entry has a lot of instructions and Machine Instruction Scheduler is enabled, the instruciton sequence will be reordered by latency.</div><div>Is it possible that an other instruction is placed between ADDrr and ADCrr? </div><div>If the placed instruction happens to update carry flag, We will get incorrect result.</div><div><br></div><div><br></div><div>Thanks,</div><div>Jerry</div><div><br></div></div><div><br></div></div><div style="margin:0;">               </div><div><br></div></div><div style="margin:0;"><br></div></div><br><br><span title="neteasefooter"><p> </p></span>