Skip to content

RedundantPhiElimination: exclude allocation instructions. #31066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/SILOptimizer/Transforms/RedundantPhiElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ bool RedundantPhiEliminationPass::valuesAreEqual(SILValue val1, SILValue val2) {
if (inst1->getMemoryBehavior() != SILInstruction::MemoryBehavior::None)
return false;

// Allocation instructions are defined to have no side-effects.
// Two allocations (even if the instruction look the same) don't define
// the same value.
if (isa<AllocationInst>(inst1))
return false;

auto *inst2 = cast<SingleValueInstruction>(val2);

// Compare the operands by putting them on the worklist.
Expand Down
20 changes: 20 additions & 0 deletions test/SILOptimizer/redundant_phi_elimination.sil
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ sil_stage canonical
import Builtin
import Swift

class X {}

// CHECK-LABEL: sil @test_simple
// CHECK: bb1:
// CHECK: br bb3(%0 : $Builtin.Int64)
Expand Down Expand Up @@ -153,3 +155,21 @@ bb3:
%r = tuple ()
return %r : $()
}

// CHECK-LABEL: sil @test_allocation_inst
// CHECK: alloc_ref
// CHECK: alloc_ref
// CHECK: bb1([[ARG1:%[0-9]+]] : $X, [[ARG2:%[0-9]+]] : $X):
// CHECK: tuple ([[ARG1]] : $X, [[ARG2]] : $X)
// CHECK: } // end sil function 'test_allocation_inst'
sil @test_allocation_inst : $@convention(thin) () -> (X, X) {
bb0:
%1 = alloc_ref $X
%2 = alloc_ref $X
br bb1(%1 : $X, %2 : $X)

bb1(%3 : $X, %4 : $X):
%r = tuple (%3 : $X, %4 : $X)
return %r : $(X, X)
}