[llvm] 363d99d - llvm-reduce: Fix not preserving uselistorder with bitcode

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 30 07:26:38 PDT 2023


Author: Matt Arsenault
Date: 2023-06-30T10:26:32-04:00
New Revision: 363d99db49a1ded7d31c7253d203f737d269ad86

URL: https://github.com/llvm/llvm-project/commit/363d99db49a1ded7d31c7253d203f737d269ad86
DIFF: https://github.com/llvm/llvm-project/commit/363d99db49a1ded7d31c7253d203f737d269ad86.diff

LOG: llvm-reduce: Fix not preserving uselistorder with bitcode

Fix accidentally passing pointer to bool argument This was supposed to
be writing bitcode with preserved uselistorder, but instead was only
enabling it with LTO module summaries.

Added: 
    llvm/test/tools/llvm-reduce/bitcode-uselistorder.ll

Modified: 
    llvm/test/tools/llvm-reduce/Inputs/llvm-dis-and-filecheck.py
    llvm/tools/llvm-reduce/ReducerWorkItem.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-reduce/Inputs/llvm-dis-and-filecheck.py b/llvm/test/tools/llvm-reduce/Inputs/llvm-dis-and-filecheck.py
index eb0c8f27dc3ed7..2244542d9b2dc7 100755
--- a/llvm/test/tools/llvm-reduce/Inputs/llvm-dis-and-filecheck.py
+++ b/llvm/test/tools/llvm-reduce/Inputs/llvm-dis-and-filecheck.py
@@ -25,7 +25,7 @@
 bitcode_file = sys.argv[-1]
 ir_file = bitcode_file + ".ll"
 
-disassemble = subprocess.Popen([llvm_dis, "-o", ir_file, bitcode_file])
+disassemble = subprocess.Popen([llvm_dis, "--preserve-ll-uselistorder", "-o", ir_file, bitcode_file])
 if os.path.exists(ir_file + ".0"):
     ir_file = ir_file + ".0"
 

diff  --git a/llvm/test/tools/llvm-reduce/bitcode-uselistorder.ll b/llvm/test/tools/llvm-reduce/bitcode-uselistorder.ll
new file mode 100644
index 00000000000000..ac98d75ef2d3be
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/bitcode-uselistorder.ll
@@ -0,0 +1,30 @@
+; RUN: llvm-as -o %t.bc %s
+
+; RUN: llvm-reduce -j=1 --abort-on-invalid-reduction \
+; RUN:   --delta-passes=instructions -o %t.reduced.bc \
+; RUN:   --test %python --test-arg %p/Inputs/llvm-dis-and-filecheck.py \
+; RUN:   --test-arg llvm-dis \
+; RUN:   --test-arg FileCheck --test-arg --check-prefix=INTERESTING \
+; RUN:   --test-arg %s %t.bc
+
+; RUN: llvm-dis --preserve-ll-uselistorder -o %t.reduced.ll %t.reduced.bc
+
+; RUN: FileCheck -check-prefix=RESULT %s < %t.reduced.ll
+
+
+; INTERESTING: add
+; INTERESTING: add
+; INTERESTING: add
+define i32 @func(i32 %arg0, i32 %arg1) {
+entry:
+  %add0 = add i32 %arg0, 0
+  %add1 = add i32 %add0, 0
+  %add2 = add i32 %add1, 0
+  %add3 = add i32 %arg1, 0
+  %add4 = add i32 %add2, %add3
+  ret i32 %add4
+}
+
+; INTERESTING: uselistorder
+; RESULT: uselistorder
+uselistorder i32 0, { 3, 2, 1, 0 }

diff  --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
index 77d8b85714976f..30852082172938 100644
--- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
+++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
@@ -734,7 +734,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const {
       Index = std::make_unique<ModuleSummaryIndex>(
           buildModuleSummaryIndex(*M, nullptr, &PSI));
     }
-    WriteBitcodeToFile(getModule(), OutStream, Index.get());
+    WriteBitcodeToFile(getModule(), OutStream,
+                       /*ShouldPreserveUseListOrder=*/true, Index.get());
   }
 }
 


        


More information about the llvm-commits mailing list