[llvm] r338134 - bpf: add missing RegState to notify MachineInstr verifier necessary register usage

Yonghong Song via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 27 09:58:53 PDT 2018


Author: yhs
Date: Fri Jul 27 09:58:52 2018
New Revision: 338134

URL: http://llvm.org/viewvc/llvm-project?rev=338134&view=rev
Log:
bpf: add missing RegState to notify MachineInstr verifier necessary register usage

Errors like the following are reported by:

  https://urldefense.proofpoint.com/v2/url?u=http-3A__lab.llvm.org-3A8011_builders_llvm-2Dclang-2Dx86-5F64-2Dexpensive-2Dchecks-2Dwin_builds_11261&d=DwIBAg&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=929oWPCf7Bf2qQnir4GBtowB8ZAlIRWsAdTfRkDaK-g&s=9k-wbEUVpUm474hhzsmAO29VXVvbxJPWD9RTgCD71fQ&e=

  *** Bad machine code: Explicit definition marked as use ***
  - function:    cal_align1
  - basic block: %bb.0 entry (0x47edd98)
  - instruction: LDB $r3, $r2, 0
  - operand 0:   $r3

This is because RegState info was missing for ScratchReg inside
expandMEMCPY. This caused incomplete register usage information to
MachineInstr verifier which then would complain as there could be potential
code-gen issue if the complained MachineInstr is used in place where
register usage information matters even though the memcpy expanding is not
in such case as it happens at the last stage of IR optimization pipeline.

We should always specify those register usage information which compiler
couldn't deduct automatically whenever we add a hardware register manually.

Reported-by: Builder llvm-clang-x86_64-expensive-checks-win Build #11261
Signed-off-by: Jiong Wang <jiong.wang at netronome.com>
Reviewed-by: Yonghong Song <yhs at fb.com>

Modified:
    llvm/trunk/lib/Target/BPF/BPFInstrInfo.cpp
    llvm/trunk/test/CodeGen/BPF/memcpy-expand-in-order.ll

Modified: llvm/trunk/lib/Target/BPF/BPFInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/BPFInstrInfo.cpp?rev=338134&r1=338133&r2=338134&view=diff
==============================================================================
--- llvm/trunk/lib/Target/BPF/BPFInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/BPF/BPFInstrInfo.cpp Fri Jul 27 09:58:52 2018
@@ -77,9 +77,11 @@ void BPFInstrInfo::expandMEMCPY(MachineB
   unsigned IterationNum = CopyLen >> Log2_64(Alignment);
   for(unsigned I = 0; I < IterationNum; ++I) {
     BuildMI(*BB, MI, dl, get(LdOpc))
-            .addReg(ScratchReg).addReg(SrcReg).addImm(I * Alignment);
+            .addReg(ScratchReg, RegState::Define).addReg(SrcReg)
+            .addImm(I * Alignment);
     BuildMI(*BB, MI, dl, get(StOpc))
-            .addReg(ScratchReg).addReg(DstReg).addImm(I * Alignment);
+            .addReg(ScratchReg, RegState::Kill).addReg(DstReg)
+            .addImm(I * Alignment);
   }
 
   unsigned BytesLeft = CopyLen & (Alignment - 1);
@@ -89,23 +91,23 @@ void BPFInstrInfo::expandMEMCPY(MachineB
   bool Hanging1Byte = BytesLeft & 0x1;
   if (Hanging4Byte) {
     BuildMI(*BB, MI, dl, get(BPF::LDW))
-            .addReg(ScratchReg).addReg(SrcReg).addImm(Offset);
+            .addReg(ScratchReg, RegState::Define).addReg(SrcReg).addImm(Offset);
     BuildMI(*BB, MI, dl, get(BPF::STW))
-            .addReg(ScratchReg).addReg(DstReg).addImm(Offset);
+            .addReg(ScratchReg, RegState::Kill).addReg(DstReg).addImm(Offset);
     Offset += 4;
   }
   if (Hanging2Byte) {
     BuildMI(*BB, MI, dl, get(BPF::LDH))
-            .addReg(ScratchReg).addReg(SrcReg).addImm(Offset);
+            .addReg(ScratchReg, RegState::Define).addReg(SrcReg).addImm(Offset);
     BuildMI(*BB, MI, dl, get(BPF::STH))
-            .addReg(ScratchReg).addReg(DstReg).addImm(Offset);
+            .addReg(ScratchReg, RegState::Kill).addReg(DstReg).addImm(Offset);
     Offset += 2;
   }
   if (Hanging1Byte) {
     BuildMI(*BB, MI, dl, get(BPF::LDB))
-            .addReg(ScratchReg).addReg(SrcReg).addImm(Offset);
+            .addReg(ScratchReg, RegState::Define).addReg(SrcReg).addImm(Offset);
     BuildMI(*BB, MI, dl, get(BPF::STB))
-            .addReg(ScratchReg).addReg(DstReg).addImm(Offset);
+            .addReg(ScratchReg, RegState::Kill).addReg(DstReg).addImm(Offset);
   }
 
   BB->erase(MI);

Modified: llvm/trunk/test/CodeGen/BPF/memcpy-expand-in-order.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/memcpy-expand-in-order.ll?rev=338134&r1=338133&r2=338134&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/memcpy-expand-in-order.ll (original)
+++ llvm/trunk/test/CodeGen/BPF/memcpy-expand-in-order.ll Fri Jul 27 09:58:52 2018
@@ -1,5 +1,5 @@
-; RUN: llc < %s -march=bpfel -bpf-expand-memcpy-in-order | FileCheck %s
-; RUN: llc < %s -march=bpfeb -bpf-expand-memcpy-in-order | FileCheck %s
+; RUN: llc < %s -march=bpfel -verify-machineinstrs -bpf-expand-memcpy-in-order | FileCheck %s
+; RUN: llc < %s -march=bpfeb -verify-machineinstrs -bpf-expand-memcpy-in-order | FileCheck %s
 ;
 ; #define COPY_LEN	9
 ;




More information about the llvm-commits mailing list