[llvm] 7721cba - llvm-reduce: Fix another invalid reduction with repeated input phis
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 7 13:15:31 PDT 2022
Author: Matt Arsenault
Date: 2022-10-07T13:15:15-07:00
New Revision: 7721cba2eeb41a45f002ee923cb7acef89fa7483
URL: https://github.com/llvm/llvm-project/commit/7721cba2eeb41a45f002ee923cb7acef89fa7483
DIFF: https://github.com/llvm/llvm-project/commit/7721cba2eeb41a45f002ee923cb7acef89fa7483.diff
LOG: llvm-reduce: Fix another invalid reduction with repeated input phis
ReduceOperandsSkip had the same issue as ReduceOperands when handling
phis with repeated predecessors.
Added:
llvm/test/tools/llvm-reduce/reduce-operands-skip-repeated-phi-input.ll
Modified:
llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-reduce/reduce-operands-skip-repeated-phi-input.ll b/llvm/test/tools/llvm-reduce/reduce-operands-skip-repeated-phi-input.ll
new file mode 100644
index 000000000000..29d88cd8377e
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/reduce-operands-skip-repeated-phi-input.ll
@@ -0,0 +1,32 @@
+; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=operands-skip --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck --check-prefixes=CHECK %s < %t
+
+; Make sure if we're replacing the value in a phi, it's replaced for
+; all repeats of the same incoming block.
+
+; CHECK-INTERESTINGNESS: switch
+; CHECK-INTERESTINGNESS: phi
+; CHECK-INTERESTINGNESS-SAME: [ %gep1, %bb1 ]
+
+; CHECK: %phi.ptr = phi ptr [ %arg1, %entry ], [ %arg1, %entry ], [ %gep1, %bb1 ]
+define void @foo(i32 %arg0, ptr %arg1, ptr %arg2) {
+entry:
+ %gep0 = getelementptr i32, ptr %arg1, i32 10
+ %gep1 = getelementptr i32, ptr %arg2, i32 12
+ switch i32 %arg0, label %ret [
+ i32 3, label %bb1
+ i32 4, label %bb2
+ i32 12, label %bb2
+ ]
+
+bb1:
+ br label %bb2
+
+bb2:
+ %phi.ptr = phi ptr [ %gep0, %entry ], [ %gep0, %entry ], [ %gep1, %bb1 ]
+ store volatile i32 0, ptr %phi.ptr
+ br label %ret
+
+ret:
+ ret void
+}
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp
index 2dd113e9cf7b..bb15a72a1581 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp
@@ -212,8 +212,12 @@ static void extractOperandsFromModule(Oracle &O, Module &Program) {
}
});
- for (std::pair<Use *, Value *> P : Replacements)
- P.first->set(P.second);
+ for (std::pair<Use *, Value *> P : Replacements) {
+ if (PHINode *Phi = dyn_cast<PHINode>(P.first->getUser()))
+ Phi->setIncomingValueForBlock(Phi->getIncomingBlock(*P.first), P.second);
+ else
+ P.first->set(P.second);
+ }
}
}
More information about the llvm-commits
mailing list