@@ -715,30 +715,29 @@ static SmallVector<SmallVector<Value, 8>, 2> pruneRedundantArguments(
715
715
716
716
// Go through the first list of arguments (list 0).
717
717
for (unsigned j = 0 ; j < numArgs; ++j) {
718
- bool shouldReplaceJ = false ;
719
- unsigned replacement = 0 ;
720
718
// Look back to see if there are possible redundancies in list 0. Please
721
719
// note that we are using a map to annotate when an argument was seen first
722
720
// to avoid a O(N^2) algorithm. This has the drawback that if we have two
723
721
// lists like:
724
722
// list0: [%a, %a, %a]
725
723
// list1: [%c, %b, %b]
726
- // We cannot simplify it, because firstVlaueToIdx [%a] = 0, but we cannot
724
+ // We cannot simplify it, because firstValueToIdx [%a] = 0, but we cannot
727
725
// point list1[1](==%b) or list1[2](==%b) to list1[0](==%c). However, since
728
726
// the number of arguments can be potentially unbounded we cannot afford a
729
727
// O(N^2) algorithm (to search to all the possible pairs) and we need to
730
728
// accept the trade-off.
731
729
unsigned k = firstValueToIdx[newArguments[0 ][j]];
732
- if (k != j) {
733
- shouldReplaceJ = true ;
734
- replacement = k;
735
- // If a possible redundancy is found, then scan the other lists: we
736
- // can prune the arguments if and only if they are redundant in every
737
- // list.
738
- for (unsigned i = 1 ; i < numLists; ++i)
739
- shouldReplaceJ =
740
- shouldReplaceJ && (newArguments[i][k] == newArguments[i][j]);
741
- }
730
+ if (k == j)
731
+ continue ;
732
+
733
+ bool shouldReplaceJ = true ;
734
+ unsigned replacement = k;
735
+ // If a possible redundancy is found, then scan the other lists: we
736
+ // can prune the arguments if and only if they are redundant in every
737
+ // list.
738
+ for (unsigned i = 1 ; i < numLists; ++i)
739
+ shouldReplaceJ =
740
+ shouldReplaceJ && (newArguments[i][k] == newArguments[i][j]);
742
741
// Save the replacement.
743
742
if (shouldReplaceJ)
744
743
idxToReplacement[j] = replacement;
@@ -918,6 +917,8 @@ static LogicalResult mergeIdenticalBlocks(RewriterBase &rewriter,
918
917
return success (anyChanged);
919
918
}
920
919
920
+ // / If a block's argument is always the same across different invocations, then
921
+ // / drop the argument and use the value directly inside the block
921
922
static LogicalResult dropRedundantArguments (RewriterBase &rewriter,
922
923
Block &block) {
923
924
SmallVector<size_t > argsToErase;
@@ -929,7 +930,7 @@ static LogicalResult dropRedundantArguments(RewriterBase &rewriter,
929
930
930
931
// Go through the block predecessor and flag if they pass to the block
931
932
// different values for the same argument.
932
- for (auto predIt = block.pred_begin (), predE = block.pred_end ();
933
+ for (Block::pred_iterator predIt = block.pred_begin (), predE = block.pred_end ();
933
934
predIt != predE; ++predIt) {
934
935
auto branch = dyn_cast<BranchOpInterface>((*predIt)->getTerminator ());
935
936
if (!branch) {
@@ -941,11 +942,11 @@ static LogicalResult dropRedundantArguments(RewriterBase &rewriter,
941
942
auto branchOperands = succOperands.getForwardedOperands ();
942
943
if (!commonValue) {
943
944
commonValue = branchOperands[argIdx];
944
- } else {
945
- if (branchOperands[argIdx] != commonValue) {
946
- sameArg = false ;
947
- break ;
948
- }
945
+ continue ;
946
+ }
947
+ if (branchOperands[argIdx] != commonValue) {
948
+ sameArg = false ;
949
+ break ;
949
950
}
950
951
}
951
952
@@ -959,7 +960,7 @@ static LogicalResult dropRedundantArguments(RewriterBase &rewriter,
959
960
}
960
961
961
962
// Remove the arguments.
962
- for (auto argIdx : llvm::reverse (argsToErase)) {
963
+ for (size_t argIdx : llvm::reverse (argsToErase)) {
963
964
block.eraseArgument (argIdx);
964
965
965
966
// Remove the argument from the branch ops.
0 commit comments