[PATCH] D32892: Handle a COPY with undef source operand in LowerCopy().

Jonas Paulsson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 5 00:00:31 PDT 2017


jonpa created this revision.

Llvm-stress discovered that a COPY may end up in ExpandPostRA::LowerCopy() with an undef source operand. It is not possible for the target to handle this, as this flag is not passed to TII->copyPhysReg().

This patch solves this by treating such a COPY as an identity COPY, as Matthias suggested on llvm-dev.

Reduces llvm-stress test case is also included.


https://reviews.llvm.org/D32892

Files:
  lib/CodeGen/ExpandPostRAPseudos.cpp
  test/CodeGen/SystemZ/lower-copy-undef-src.ll


Index: test/CodeGen/SystemZ/lower-copy-undef-src.ll
===================================================================
--- /dev/null
+++ test/CodeGen/SystemZ/lower-copy-undef-src.ll
@@ -0,0 +1,43 @@
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z13 -join-liveintervals=false -verify-machineinstrs | FileCheck %s
+;
+; Test that a COPY with an undef source operand gets handled like an identity
+; copy rather than lowered into a target instruction with the undef flag
+; dropped.
+
+define void @autogen_SD13338(i8*, i32*, i64*, i32, i64, i8) {
+; CHECK: .text
+BB:
+  %L5 = load <4 x i32>, <4 x i32>* undef
+  %L30 = load i8, i8* %0
+  %B42 = sdiv i64 undef, undef
+  %L45 = load <4 x i32>, <4 x i32>* undef
+  br label %CF284
+
+CF284:                                            ; preds = %CF284, %BB
+  %L52 = load i8, i8* %0
+  %B56 = udiv i64 %B42, %4
+  %Sl57 = select i1 true, i1 undef, i1 undef
+  br i1 %Sl57, label %CF284, label %CF294
+
+CF294:                                            ; preds = %CF284
+  br label %CF
+
+CF:                                               ; preds = %CF, %CF294
+  %L94 = load i8, i8* %0
+  store i8 0, i8* %0
+  %B127 = urem <4 x i32> %L5, %L45
+  %E132 = extractelement <4 x i1> zeroinitializer, i32 0
+  br i1 %E132, label %CF, label %CF273
+
+CF273:                                            ; preds = %CF
+  %B150 = lshr i64 undef, %B56
+  %B212 = xor <4 x i32> %L5, %B127
+  %PC = bitcast i64* %2 to i8*
+  store i8 %L30, i8* %PC
+  store i8 %L94, i8* %PC
+  br label %CF275
+
+CF275:                                            ; preds = %CF275, %CF273
+  store i8 %L52, i8* %PC
+  br label %CF275
+}
Index: lib/CodeGen/ExpandPostRAPseudos.cpp
===================================================================
--- lib/CodeGen/ExpandPostRAPseudos.cpp
+++ lib/CodeGen/ExpandPostRAPseudos.cpp
@@ -142,8 +142,9 @@
   MachineOperand &DstMO = MI->getOperand(0);
   MachineOperand &SrcMO = MI->getOperand(1);
 
-  if (SrcMO.getReg() == DstMO.getReg()) {
-    DEBUG(dbgs() << "identity copy: " << *MI);
+  bool IdentityCopy = (SrcMO.getReg() == DstMO.getReg());
+  if (IdentityCopy || SrcMO.isUndef()) {
+    DEBUG(dbgs() << (IdentityCopy ? "identity copy: " : "undef copy:    ") << *MI);
     // No need to insert an identity copy instruction, but replace with a KILL
     // if liveness is changed.
     if (SrcMO.isUndef() || MI->getNumOperands() > 2) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32892.97914.patch
Type: text/x-patch
Size: 2406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170505/7c3e32a9/attachment.bin>


More information about the llvm-commits mailing list