[PATCH] D135407: llvm-reduce: Fix another invalid reduction with repeated input phis
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 6 15:06:22 PDT 2022
arsenm created this revision.
arsenm added reviewers: lebedev.ri, aeubanks, regehr, Meinersbur.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
ReduceOperandsSkip had the same issue as ReduceOperands when handling
phis with repeated predecessors.
https://reviews.llvm.org/D135407
Files:
llvm/test/tools/llvm-reduce/reduce-operands-skip-repeated-phi-input.ll
llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp
Index: llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp
+++ llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp
@@ -212,8 +212,12 @@
}
});
- 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);
+ }
}
}
Index: llvm/test/tools/llvm-reduce/reduce-operands-skip-repeated-phi-input.ll
===================================================================
--- /dev/null
+++ 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
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135407.465892.patch
Type: text/x-patch
Size: 1892 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221006/93d91a4c/attachment.bin>
More information about the llvm-commits
mailing list