<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Hi all,</p>
<p>I am trying to implement an instrinsic inside the backend through CustomInserter.</p>
<p>The raw IR code:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<p># Machine code for function main: SSA<br />Frame Objects:<br /> fi#0: size=4, align=4, at location [SP+8]<br /> fi#1: size=8, align=8, at location [SP+8]<br /><br />BB#0: derived from LLVM BB %entry<br /> %vreg4<def> = MOV64ri <ga:@.str>; GR64:%vreg4<br /> MOV32mi <fi#0>, 1, %noreg, 0, %noreg, 0; mem:ST4[%retval]<br /> <span style="color: #ff0000;">MYINTRINSIC %EFLAGS<imp-def,dead></span><br /> <span style="color: #ff0000;">MOV64mr <fi#1>, 1, %noreg, 0, %noreg, %vreg4; mem:ST8[%test] GR64:%vreg4</span><br /> %vreg3<def> = MOV64rm <fi#1>, 1, %noreg, 0, %noreg; mem:LD8[%test] GR64:%vreg3<br /> ADJCALLSTACKDOWN64 0, %RSP<imp-def>, %EFLAGS<imp-def>, %RSP<imp-use><br /> %RDI<def> = COPY %vreg3; GR64:%vreg3<br /> %AL<def> = MOV8ri 0<br /> CALL64pcrel32 <ga:@printf>, <regmask>, %RSP<imp-use>, %AL<imp-use>, %RDI<imp-use>, %EAX<imp-def><br /> ADJCALLSTACKUP64 0, 0, %RSP<imp-def>, %EFLAGS<imp-def>, %RSP<imp-use><br /> %vreg2<def> = COPY %EAX; GR32:%vreg2<br /> %vreg0<def> = MOV32r0 %EFLAGS<imp-def>; GR32:%vreg0<br /> %EAX<def> = COPY %vreg0; GR32:%vreg0<br /> RETQ %EAX<imp-use><br /><br /># End machine code for function main.</p>
</blockquote>
<p>My intrinsic is MYINTRINSIC. I would like to split into two BB at the location of MYINTRINSIC.</p>
<p>To illustrate my problem, I added a XOR followed by a JMP to the next BB.</p>
<p>My result:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<p># Machine code for function main: SSA<br />Frame Objects:<br /> fi#0: size=4, align=4, at location [SP+8]<br /> fi#1: size=8, align=8, at location [SP+8]<br /><br />BB#0: derived from LLVM BB %entry<br /> %vreg4<def> = MOV64ri <ga:@.str>; GR64:%vreg4<br /> MOV32mi <fi#0>, 1, %noreg, 0, %noreg, 0; mem:ST4[%retval]<br /> <span style="color: #ff0000;">%EDX<def,tied1> = XOR32rr %EDX<tied0>, %EDX, %EFLAGS<imp-def></span><br /><span style="color: #ff0000;"> JMP_1 <BB#1></span><br /> Successors according to CFG: BB#1<br /><br />BB#1: derived from LLVM BB %entry<br /> Predecessors according to CFG: BB#0<br /> <span style="color: #ff0000;">MOV64mr <fi#1>, 1, %noreg, 0, %noreg, %vreg4; mem:ST8[%test] GR64:%vreg4</span><br /> %vreg3<def> = MOV64rm <fi#1>, 1, %noreg, 0, %noreg; mem:LD8[%test] GR64:%vreg3<br /> ADJCALLSTACKDOWN64 0, %RSP<imp-def>, %EFLAGS<imp-def>, %RSP<imp-use><br /> %RDI<def> = COPY %vreg3; GR64:%vreg3<br /> %AL<def> = MOV8ri 0<br /> CALL64pcrel32 <ga:@printf>, <regmask>, %RSP<imp-use>, %AL<imp-use>, %RDI<imp-use>, %EAX<imp-def><br /> ADJCALLSTACKUP64 0, 0, %RSP<imp-def>, %EFLAGS<imp-def>, %RSP<imp-use><br /> %vreg2<def> = COPY %EAX; GR32:%vreg2<br /> %vreg0<def> = MOV32r0 %EFLAGS<imp-def>; GR32:%vreg0<br /> %EAX<def> = COPY %vreg0; GR32:%vreg0<br /> RETQ %EAX<imp-use><br /><br /># End machine code for function main.</p>
</blockquote>
<p>My problem is the MOV64mr of the second BB. From an IR view, it seems okay, but when I look at the generated ASM, it has been moved into the first BB. More precisely, it stand between my XOR and the JMP.</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<p> 0x00000000004005c0 <+0>: push rbp<br /> 0x00000000004005c1 <+1>: mov rbp,rsp<br /> 0x00000000004005c4 <+4>: sub rsp,0x20<br /> 0x00000000004005c8 <+8>: movabs rax,0x400694<br /> 0x00000000004005d2 <+18>: mov DWORD PTR [rbp-0x4],0x0<br /> 0x00000000004005d9 <+25>: <span style="color: #ff0000;">xor edx,edx</span><br /> 0x00000000004005db <+27>: <span style="color: #ff0000;">mov QWORD PTR [rbp-0x18],rax</span><br /> 0x00000000004005df <+31>: <span style="color: #ff0000;"> jmp 0x4005e4 <main+36></span><br /> 0x00000000004005e4 <+36>: mov rax,QWORD PTR [rbp-0x18]<br /> 0x00000000004005e8 <+40>: mov QWORD PTR [rbp-0x10],rax<br /> 0x00000000004005ec <+44>: mov rdi,QWORD PTR [rbp-0x10]<br /> 0x00000000004005f0 <+48>: mov al,0x0<br /> 0x00000000004005f2 <+50>: call 0x400490 <printf@plt><br /> 0x00000000004005f7 <+55>: xor ecx,ecx<br /> 0x00000000004005f9 <+57>: mov DWORD PTR [rbp-0x1c],eax<br /> 0x00000000004005fc <+60>: mov eax,ecx<br /> 0x00000000004005fe <+62>: add rsp,0x20<br /> 0x0000000000400602 <+66>: pop rbp<br /> 0x0000000000400603 <+67>: ret</p>
</blockquote>
<p> </p>
<p>In this case, it has no impact. But I would like to add more code right before the JMP and so I need a solution to move this MOV64mr before or after my own code but not inbetween.</p>
<p>Any idea?</p>
<p> </p>
<p>Gael</p>
<div> </div>
</body></html>