[PATCH] D57773: GlobalISel: Verify G_GEP

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 5 11:26:56 PST 2019


arsenm created this revision.
arsenm added reviewers: paquette, aemerson, aditya_nandakumar, volkan, dsanders.
Herald added subscribers: Petar.Avramovic, kristof.beyls, rovka, wdng.

https://reviews.llvm.org/D57773

Files:
  lib/CodeGen/MachineVerifier.cpp
  test/Verifier/test_g_gep.mir


Index: test/Verifier/test_g_gep.mir
===================================================================
--- /dev/null
+++ test/Verifier/test_g_gep.mir
@@ -0,0 +1,32 @@
+#RUN: not llc -o -  -run-pass=none -verify-machineinstrs %s 2>&1 | FileCheck %s
+# REQUIRES: global-isel, aarch64-registered-target
+
+---
+name:            test_gep
+legalized:       true
+regBankSelected: false
+selected:        false
+tracksRegLiveness: true
+liveins:
+body:             |
+  bb.0:
+
+    %0:_(p0) = G_IMPLICIT_DEF
+    %1:_(s64) = G_IMPLICIT_DEF
+
+    ; CHECK:  Bad machine code: Type mismatch in generic instruction
+    %2:_(s64) = G_GEP %0, %1
+
+    ; CHECK:  Bad machine code: Type mismatch in generic instruction
+    %3:_(p0) = G_GEP %1, %1
+
+    ; CHECK: Bad machine code: gep offset operand must not be a pointer
+    %4:_(p0) = G_GEP %0, %0
+
+    ; CHECK: Bad machine code: Type mismatch in generic instruction
+    %5:_(p1) = G_GEP %0, %1
+
+    ; CHECK: Bad machine code: gep first operand must be a pointer
+    %6:_(s64) = G_GEP %1, %1
+
+...
Index: lib/CodeGen/MachineVerifier.cpp
===================================================================
--- lib/CodeGen/MachineVerifier.cpp
+++ lib/CodeGen/MachineVerifier.cpp
@@ -1100,6 +1100,22 @@
 
     break;
   }
+  case TargetOpcode::G_GEP: {
+    LLT DstTy = MRI->getType(MI->getOperand(0).getReg());
+    LLT PtrTy = MRI->getType(MI->getOperand(1).getReg());
+    LLT OffsetTy = MRI->getType(MI->getOperand(2).getReg());
+    if (!DstTy.isValid() || !PtrTy.isValid() || !OffsetTy.isValid())
+      break;
+
+    if (!PtrTy.getScalarType().isPointer())
+      report("gep first operand must be a pointer", MI);
+
+    if (OffsetTy.getScalarType().isPointer())
+      report("gep offset operand must not be a pointer", MI);
+
+    // TODO: Is the offset allowed to be a scalar with a vector?
+    break;
+  }
   case TargetOpcode::G_SEXT:
   case TargetOpcode::G_ZEXT:
   case TargetOpcode::G_ANYEXT:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57773.185359.patch
Type: text/x-patch
Size: 1960 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190205/8b8d56ab/attachment.bin>


More information about the llvm-commits mailing list