[llvm] r251622 - [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 29 03:17:18 PDT 2015


Author: vkalintiris
Date: Thu Oct 29 05:17:16 2015
New Revision: 251622

URL: http://llvm.org/viewvc/llvm-project?rev=251622&view=rev
Log:
[mips] Check the register class before replacing materializations of zero with $zero in microMIPS.

Summary:
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.

Reviewers: dsanders

Subscribers: llvm-commits, dsanders

Differential Revision: http://reviews.llvm.org/D13984

Added:
    llvm/trunk/test/CodeGen/Mips/micromips-zero-mat-uses.ll
Modified:
    llvm/trunk/lib/Target/Mips/MipsSEISelDAGToDAG.cpp

Modified: llvm/trunk/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsSEISelDAGToDAG.cpp?rev=251622&r1=251621&r2=251622&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsSEISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsSEISelDAGToDAG.cpp Thu Oct 29 05:17:16 2015
@@ -115,6 +115,11 @@ bool MipsSEDAGToDAGISel::replaceUsesWith
     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);
   }
 

Added: llvm/trunk/test/CodeGen/Mips/micromips-zero-mat-uses.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/micromips-zero-mat-uses.ll?rev=251622&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/micromips-zero-mat-uses.ll (added)
+++ llvm/trunk/test/CodeGen/Mips/micromips-zero-mat-uses.ll Thu Oct 29 05:17:16 2015
@@ -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
+}




More information about the llvm-commits mailing list