[PATCH] D47437: [PowerPC] Fix the incorrect iterator inside peephole

Qing Shan Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 27 22:59:33 PDT 2018


steven.zhang created this revision.
steven.zhang added a reviewer: hfinkel.
Herald added subscribers: kbarton, hiraditya.

Instruction selection will insert nodes into the underlying list after the root node and iterating will thereby miss it. We should NOT assume that, the root node is the last element in the DAG nodelist.


https://reviews.llvm.org/D47437

Files:
  llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
  llvm/test/CodeGen/PowerPC/ppcf128-endian.ll


Index: llvm/test/CodeGen/PowerPC/ppcf128-endian.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/ppcf128-endian.ll
+++ llvm/test/CodeGen/PowerPC/ppcf128-endian.ll
@@ -43,10 +43,10 @@
 ; CHECK: .LCPI[[LC]]_1:
 ; CHECK: .long   0
 ; CHECK: @caller_const
-; CHECK: addi [[REG0:[0-9]+]], {{[0-9]+}}, .LCPI[[LC]]_0
-; CHECK: addi [[REG1:[0-9]+]], {{[0-9]+}}, .LCPI[[LC]]_1
-; CHECK: lfs 1, 0([[REG0]])
-; CHECK: lfs 2, 0([[REG1]])
+; CHECK: addis [[REG0:[0-9]+]], 2, .LCPI[[LC]]_0 at toc@ha
+; CHECK: addis [[REG1:[0-9]+]], 2, .LCPI[[LC]]_1 at toc@ha
+; CHECK: lfs 1, .LCPI[[LC]]_0 at toc@l([[REG0]])
+; CHECK: lfs 2, .LCPI[[LC]]_1 at toc@l([[REG1]])
 ; CHECK: bl test
 
 define ppc_fp128 @result() {
Index: llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
+++ llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
@@ -5169,8 +5169,7 @@
 }
 
 void PPCDAGToDAGISel::PreprocessISelDAG() {
-  SelectionDAG::allnodes_iterator Position(CurDAG->getRoot().getNode());
-  ++Position;
+  SelectionDAG::allnodes_iterator Position = CurDAG->allnodes_end();
 
   bool MadeChange = false;
   while (Position != CurDAG->allnodes_begin()) {
@@ -5858,8 +5857,7 @@
   // unnecessary. When that happens, we remove it here, and redefine the
   // relevant 32-bit operation to be a 64-bit operation.
 
-  SelectionDAG::allnodes_iterator Position(CurDAG->getRoot().getNode());
-  ++Position;
+  SelectionDAG::allnodes_iterator Position = CurDAG->allnodes_end();
 
   bool MadeChange = false;
   while (Position != CurDAG->allnodes_begin()) {
@@ -6016,8 +6014,7 @@
   if (PPCSubTarget->isDarwin() || !PPCSubTarget->isPPC64())
     return;
 
-  SelectionDAG::allnodes_iterator Position(CurDAG->getRoot().getNode());
-  ++Position;
+  SelectionDAG::allnodes_iterator Position = CurDAG->allnodes_end();
 
   while (Position != CurDAG->allnodes_begin()) {
     SDNode *N = &*--Position;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47437.148775.patch
Type: text/x-patch
Size: 1997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180528/63d76465/attachment.bin>


More information about the llvm-commits mailing list