Skip to content

[SILOptimizer] Removing identity zextOrBitCast_T_T instructions #6134

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
Dec 8, 2016
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
3 changes: 2 additions & 1 deletion lib/SILOptimizer/Analysis/SimplifyInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,10 @@ static SILValue simplifyBuiltin(BuiltinInst *BI) {
switch (Builtin.ID) {
default: break;

case BuiltinValueKind::ZExtOrBitCast:
case BuiltinValueKind::SExtOrBitCast: {
const SILValue &Op = Args[0];
// extOrBitCast_N_N(x) -> x
// [s|z]extOrBitCast_N_N(x) -> x
if (Op->getType() == BI->getType())
return Op;
}
Expand Down
11 changes: 11 additions & 0 deletions test/SILOptimizer/sil_simplify_instrs.sil
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ bb0(%x : $Builtin.Int64):
// CHECK: return %0 : $Builtin.Int64
}

// Simplify zext((x)) -> x with same type
sil @fold_zext_n_to_n : $@convention(thin) (Builtin.Int64) -> Builtin.Int64 {
bb0(%x : $Builtin.Int64):
%trunc = builtin "zextOrBitCast_Int64_Int64"(%x : $Builtin.Int64) : $Builtin.Int64
return %trunc : $Builtin.Int64

// CHECK-LABEL: sil @fold_zext_n_to_n
// CHECK-NOT: builtin
// CHECK: return %0 : $Builtin.Int64
}

class IntClass {
@sil_stored var value: Builtin.Int32 { get set }
init(value: Builtin.Int32)
Expand Down