Skip to content

Commit a10a0e1

Browse files
authored
[SILOptimizer] Removing identity zextOrBitCast_T_T instructions (#6134)
1 parent 49d3b73 commit a10a0e1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/SILOptimizer/Analysis/SimplifyInstruction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,10 @@ static SILValue simplifyBuiltin(BuiltinInst *BI) {
477477
switch (Builtin.ID) {
478478
default: break;
479479

480+
case BuiltinValueKind::ZExtOrBitCast:
480481
case BuiltinValueKind::SExtOrBitCast: {
481482
const SILValue &Op = Args[0];
482-
// extOrBitCast_N_N(x) -> x
483+
// [s|z]extOrBitCast_N_N(x) -> x
483484
if (Op->getType() == BI->getType())
484485
return Op;
485486
}

test/SILOptimizer/sil_simplify_instrs.sil

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ bb0(%x : $Builtin.Int64):
118118
// CHECK: return %0 : $Builtin.Int64
119119
}
120120

121+
// Simplify zext((x)) -> x with same type
122+
sil @fold_zext_n_to_n : $@convention(thin) (Builtin.Int64) -> Builtin.Int64 {
123+
bb0(%x : $Builtin.Int64):
124+
%trunc = builtin "zextOrBitCast_Int64_Int64"(%x : $Builtin.Int64) : $Builtin.Int64
125+
return %trunc : $Builtin.Int64
126+
127+
// CHECK-LABEL: sil @fold_zext_n_to_n
128+
// CHECK-NOT: builtin
129+
// CHECK: return %0 : $Builtin.Int64
130+
}
131+
121132
class IntClass {
122133
@sil_stored var value: Builtin.Int32 { get set }
123134
init(value: Builtin.Int32)

0 commit comments

Comments
 (0)