<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/source/rss.xsl.xml"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
    <title>Changes in offset-reloc-simplify-patchable-2.ll</title>
    <description></description>
    <language>en</language>
    <copyright>Copyright 2015</copyright>
    <generator>Java</generator><item>
        <title>08d92dedd26c66bd203cc3b45f982d7aeb214995 - [BPF] Fix in/out argument constraints for CORE_MEM instructions</title>
        <link>http://src.rcs.uwaterloo.ca:8080/source/history/llvm-project/llvm/test/CodeGen/BPF/CORE/offset-reloc-simplify-patchable-2.ll#08d92dedd26c66bd203cc3b45f982d7aeb214995</link>
        <description>[BPF] Fix in/out argument constraints for CORE_MEM instructionsWhen LLVM is build with `LLVM_ENABLE_EXPENSIVE_CHECKS=ON` option thefollowing C code snippet:    struct t {      int a;    } __attribute__((preserve_access_index));    void test(struct t *t) {      t-&gt;a = 42;    }Causes an assertion:$ clang -g -O2 -c --target=bpf -mcpu=v2 t.c -o /dev/nullFunction Live Ins: $r1 in %0bb.0.entry:  liveins: $r1  DBG_VALUE $r1, $noreg, !&quot;t&quot;, ...  %0:gpr = COPY $r1  DBG_VALUE %0:gpr, $noreg, !&quot;t&quot;, ...  %1:gpr = LD_imm64 @&quot;llvm.t:0:0$0:0&quot;  %3:gpr = ADD_rr %0:gpr(tied-def 0), killed %1:gpr  %4:gpr = MOV_ri 42  CORE_MEM killed %4:gpr, 411, %0:gpr, @&quot;llvm.t:0:0$0:0&quot;, ...  RET debug-location !25; t.c:7:1*** Bad machine code: Explicit definition marked as use ***- function:    test- basic block: %bb.0 entry (0x6210000d8a90)- instruction: CORE_MEM killed %4:gpr, 411, %0:gpr, @&quot;llvm.t:0:0$0:0&quot;, ...- operand 0:   killed %4:gprThis happens because `CORE_MEM` instruction is defined to have outputoperands:  def CORE_MEM : TYPE_LD_ST&lt;BPF_MEM.Value, BPF_W.Value,                            (outs GPR:$dst),                            (ins u64imm:$opcode, GPR:$src, u64imm:$offset),                            &quot;$dst = core_mem($opcode, $src, $offset)&quot;,                            []&gt;;As documented in [1]:&gt; By convention, the LLVM code generator orders instruction operands&gt; so that all register definitions come before the register uses, even&gt; on architectures that are normally printed in other orders.In other words, the first argument for `CORE_MEM` is considered to bea &quot;def&quot;, while in reality it is &quot;use&quot;:  %1:gpr = LD_imm64 @&quot;llvm.t:0:0$0:0&quot;  %3:gpr = ADD_rr %0:gpr(tied-def 0), killed %1:gpr  %4:gpr = MOV_ri 42   &apos;---------------.                   v  CORE_MEM killed %4:gpr, 411, %0:gpr, @&quot;llvm.t:0:0$0:0&quot;, ...Here is how `CORE_MEM` is constructed in`BPFMISimplifyPatchable::checkADDrr()`:    BuildMI(*DefInst-&gt;getParent(), *DefInst, DefInst-&gt;getDebugLoc(), TII-&gt;get(COREOp))        .add(DefInst-&gt;getOperand(0)).addImm(Opcode).add(*BaseOp)        .addGlobalAddress(GVal);Note that first operand is constructed as `.add(DefInst-&gt;getOperand(0))`.For `LD{D,W,H,B}` instructions the `DefInst-&gt;getOperand(0)` is adestination register of a load, so instruction is constructed inaccordance with `outs` declaration.For `ST{D,W,H,B}` instructions the `DefInst-&gt;getOperand(0)` is asource register of a store (value to be stored), so instructionviolates the `outs` declaration.This commit fixes the issue by splitting `CORE_MEM` in threeinstructions: `CORE_ST`, `CORE_LD64`, `CORE_LD32` with correct `outs`specifications.[1] https://llvm.org/docs/CodeGenerator.html#the-machineinstr-classDifferential Revision: https://reviews.llvm.org/D157806

            List of files:
            /llvm-project/llvm/test/CodeGen/BPF/CORE/offset-reloc-simplify-patchable-2.ll</description>
        <pubDate>Sun, 13 Aug 2023 16:52:21 +0000</pubDate>
        <dc:creator>Eduard Zingerman &lt;eddyz87@gmail.com&gt;</dc:creator>
    </item>
</channel>
</rss>
