[PATCH] D13984: [mips] Check the register class before replacing materializations of zero with $zero in microMIPS.

Vasileios Kalintiris via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 22 06:49:22 PDT 2015


vkalintiris created this revision.
vkalintiris added a reviewer: dsanders.
vkalintiris added a subscriber: llvm-commits.
Herald added a subscriber: dsanders.

The microMIPS register class GPRMM16 does not contain the $zero register.
However, MipsSEDAGToDAGISel::replaceUsesWithZeroReg() would replace uses
of the $dst register:

  [d]addiu, $dst, $zero, 0

with the $zero register, without checking for membership in the register
class of the target machine operand.

http://reviews.llvm.org/D13984

Files:
  lib/Target/Mips/MipsSEISelDAGToDAG.cpp
  test/CodeGen/Mips/micromips-zero-mat-uses.ll

Index: test/CodeGen/Mips/micromips-zero-mat-uses.ll
===================================================================
--- /dev/null
+++ test/CodeGen/Mips/micromips-zero-mat-uses.ll
@@ -0,0 +1,8 @@
+; RUN: llc -march=mips -mcpu=mips32r2 -mattr=+micromips,+nooddspreg -O0 < %s | FileCheck %s
+
+; CHECK: addiu    $[[R0:[0-9]+]], $zero, 0
+; CHECK: subu16   $2, $[[R0]], ${{[0-9]+}}
+define i32 @foo() {
+  %1 = sub i32 0, undef
+  ret i32 %1
+}
Index: lib/Target/Mips/MipsSEISelDAGToDAG.cpp
===================================================================
--- lib/Target/Mips/MipsSEISelDAGToDAG.cpp
+++ lib/Target/Mips/MipsSEISelDAGToDAG.cpp
@@ -115,6 +115,11 @@
     if (MI->isPHI() || MI->isRegTiedToDefOperand(OpNo) || MI->isPseudo())
       continue;
 
+    // Also, we have to check that the register class of the operand
+    // contains the zero register.
+    if (!MRI->getRegClass(MO.getReg())->contains(ZeroReg))
+      continue;
+
     MO.setReg(ZeroReg);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13984.38124.patch
Type: text/x-patch
Size: 977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151022/ad7cf4f7/attachment.bin>


More information about the llvm-commits mailing list