[PATCH] D119934: [RISCV] Fix a mistake in PostprocessISelDAG

Ben Shi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 25 04:38:51 PST 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG865fe131f87c: [RISCV] Fix a mistake in PostprocessISelDAG (authored by Luhaocong, committed by benshi001).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119934/new/

https://reviews.llvm.org/D119934

Files:
  llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
  llvm/test/CodeGen/RISCV/fold-addi-loadstore.ll


Index: llvm/test/CodeGen/RISCV/fold-addi-loadstore.ll
===================================================================
--- llvm/test/CodeGen/RISCV/fold-addi-loadstore.ll
+++ llvm/test/CodeGen/RISCV/fold-addi-loadstore.ll
@@ -166,6 +166,37 @@
    ret void
 }
 
+; Check if we can fold ADDI into the offset of store instructions,
+; when store instructions is the root node in DAG.
+
+ at g_4_i32 = global i32 0, align 4
+
+define dso_local void @inc_g_i32() nounwind {
+; RV32I-LABEL: inc_g_i32:
+; RV32I:       # %bb.0: # %entry
+; RV32I-NEXT:    lui a0, %hi(g_4_i32)
+; RV32I-NEXT:    lw a1, %lo(g_4_i32)(a0)
+; RV32I-NEXT:    addi a1, a1, 1
+; RV32I-NEXT:    sw a1, %lo(g_4_i32)(a0)
+; RV32I-NEXT:    ret
+;
+; RV64I-LABEL: inc_g_i32:
+; RV64I:       # %bb.0: # %entry
+; RV64I-NEXT:    lui a0, %hi(g_4_i32)
+; RV64I-NEXT:    lw a1, %lo(g_4_i32)(a0)
+; RV64I-NEXT:    addiw a1, a1, 1
+; RV64I-NEXT:    sw a1, %lo(g_4_i32)(a0)
+; RV64I-NEXT:    ret
+entry:
+  %0 = load i32, i32* @g_4_i32
+  %inc = add i32 %0, 1
+  store i32 %inc, i32* @g_4_i32
+  br label %if.end
+
+if.end:
+  ret void
+}
+
 ; Check for folds in accesses to the second element of an i64 array.
 
 @ga_8 = dso_local local_unnamed_addr global [2 x i64] zeroinitializer, align 8
Index: llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -132,6 +132,7 @@
 }
 
 void RISCVDAGToDAGISel::PostprocessISelDAG() {
+  HandleSDNode Dummy(CurDAG->getRoot());
   SelectionDAG::allnodes_iterator Position = CurDAG->allnodes_end();
 
   bool MadeChange = false;
@@ -146,6 +147,8 @@
     MadeChange |= doPeepholeMaskedRVV(N);
   }
 
+  CurDAG->setRoot(Dummy.getValue());
+
   if (MadeChange)
     CurDAG->RemoveDeadNodes();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119934.411380.patch
Type: text/x-patch
Size: 1841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220225/42ec317c/attachment.bin>


More information about the llvm-commits mailing list