[PATCH] D62713: [MIR-Canon] Hardening propagateLocalCopies.

Puyan Lotfi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 30 19:00:34 PDT 2019


plotfi marked an inline comment as done.
plotfi added inline comments.


================
Comment at: llvm/lib/CodeGen/MIRCanonicalizerPass.cpp:345
       continue;
+    // Not folding COPY instructions if regbankselect has not set the RCs.
+    if (nullptr == MRI.getRegClassOrNull(Dst))
----------------
compnerd wrote:
> Can you explain why the type along isn't sufficient
Because in some cases like:

```
    %namedVReg4353:sreg_32_xm0 = S_MOV_B32 0
    %namedVReg1352:vgpr_32 = COPY %namedVReg4353
    ...
    BUFFER_STORE_DWORD_ADDR64 %namedVReg1352, %namedVReg1353, %namedVReg1354, 0, 0, 0, 0, 0, 0, implicit $exec

```

Folding the copy causes a verifier error even though the types are the same:

```

  %namedVReg4353:sreg_32_xm0 = S_MOV_B32 0
  ...
  BUFFER_STORE_DWORD_ADDR64 %namedVReg4353:sreg_32_xm0, %namedVReg1353:vreg_64, %namedVReg1354:sgpr_128, 0, 0, 0, 0, 0, 0, implicit $exec
  S_ENDPGM 0

*** Bad machine code: Illegal virtual register for instruction ***
- function:    foo
- basic block: %bb.0  (0x559c6b1fa878)
- instruction: BUFFER_STORE_DWORD_ADDR64 %namedVReg4353:sreg_32_xm0, %namedVReg1353:vreg_64, %namedVReg1354:sgpr_128, 0, 0, 0, 0, 0, 0, implicit $exec
- operand 0:   %namedVReg4353:sreg_32_xm0
Expected a VGPR_32 register, but got a SReg_32_XM0 register
LLVM ERROR: Found 1 machine code errors.
```

I think the right way is only to fold on matching types if regbankselect has not happened (in the case where there is no register class), which I will probably add in a different commit. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62713/new/

https://reviews.llvm.org/D62713





More information about the llvm-commits mailing list