File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
lib/SILOptimizer/Analysis Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -477,9 +477,20 @@ static SILValue simplifyBuiltin(BuiltinInst *BI) {
477
477
switch (Builtin.ID ) {
478
478
default : break ;
479
479
480
+ case BuiltinValueKind::SExtOrBitCast: {
481
+ const SILValue &Op = Args[0 ];
482
+ // extOrBitCast_N_N(x) -> x
483
+ if (Op->getType () == BI->getType ())
484
+ return Op;
485
+ }
486
+ break ;
487
+
480
488
case BuiltinValueKind::TruncOrBitCast: {
481
489
const SILValue &Op = Args[0 ];
482
490
SILValue Result;
491
+ // truncOrBitCast_N_N(x) -> x
492
+ if (Op->getType () == BI->getType ())
493
+ return Op;
483
494
// trunc(extOrBitCast(x)) -> x
484
495
if (match (Op, m_ExtOrBitCast (m_SILValue (Result)))) {
485
496
// Truncated back to the same bits we started with.
Original file line number Diff line number Diff line change @@ -96,6 +96,28 @@ bb0(%x : $Builtin.Word):
96
96
// CHECK: return %0 : $Builtin.Word
97
97
}
98
98
99
+ // Simplify trunc((x)) -> x with same type
100
+ sil @fold_trunc_n_to_n : $@convention(thin) (Builtin.Int64) -> Builtin.Int64 {
101
+ bb0(%x : $Builtin.Int64):
102
+ %trunc = builtin "truncOrBitCast_Int64_Word"(%x : $Builtin.Int64) : $Builtin.Int64
103
+ return %trunc : $Builtin.Int64
104
+
105
+ // CHECK-LABEL: sil @fold_trunc_n_to_n
106
+ // CHECK-NOT: builtin
107
+ // CHECK: return %0 : $Builtin.Int64
108
+ }
109
+
110
+ // Simplify sext((x)) -> x with same type
111
+ sil @fold_sext_n_to_n : $@convention(thin) (Builtin.Int64) -> Builtin.Int64 {
112
+ bb0(%x : $Builtin.Int64):
113
+ %trunc = builtin "sextOrBitCast_Int64_Int64"(%x : $Builtin.Int64) : $Builtin.Int64
114
+ return %trunc : $Builtin.Int64
115
+
116
+ // CHECK-LABEL: sil @fold_sext_n_to_n
117
+ // CHECK-NOT: builtin
118
+ // CHECK: return %0 : $Builtin.Int64
119
+ }
120
+
99
121
class IntClass {
100
122
@sil_stored var value: Builtin.Int32 { get set }
101
123
init(value: Builtin.Int32)
You can’t perform that action at this time.
0 commit comments