Skip to content

Commit 121aa40

Browse files
authored
Merge pull request #82012 from eeckstein/fix-licm-6.2
LICM: fix a wrong tuple type when splitting loads
2 parents 0d5351b + 9be5e2d commit 121aa40

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/SILOptimizer/LoopTransforms/LICM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ SingleValueInstruction *LoopTreeOptimization::splitLoad(
11481148
}
11491149
elements.push_back(elementVal);
11501150
}
1151-
return builder.createTuple(loc, elements);
1151+
return builder.createTuple(loc, loadTy.getObjectType(), elements);
11521152
}
11531153
auto structTy = loadTy.getStructOrBoundGenericStruct();
11541154
assert(structTy && "tuple and struct elements are checked earlier");

test/SILOptimizer/licm.sil

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ struct S {
2323
var s: String
2424
}
2525

26+
struct Pair {
27+
var t: (a: Int, b: Int)
28+
}
29+
2630
// globalArray
2731
sil_global @globalArray : $Storage
2832

@@ -1704,3 +1708,30 @@ bb4(%14 : @reborrow $S):
17041708
return %r
17051709
}
17061710

1711+
// Just check that LICM doesn't produce invalid SIL because of a tuple type mismatch.
1712+
// CHECK-LABEL: sil [ossa] @split_load_of_labeld_tuples :
1713+
// CHECK-LABEL: } // end sil function 'split_load_of_labeld_tuples'
1714+
sil [ossa] @split_load_of_labeld_tuples : $@convention(thin) (@inout Pair, Int) -> () {
1715+
bb0(%0 : $*Pair, %1 : $Int):
1716+
br bb1
1717+
1718+
bb1:
1719+
cond_br undef, bb3, bb2
1720+
1721+
bb2:
1722+
%4 = load [trivial] %0
1723+
%5 = struct_element_addr %0, #Pair.t
1724+
%6 = tuple_element_addr %5, 0
1725+
%7 = alloc_stack $Int
1726+
store %1 to [trivial] %7
1727+
%9 = load [trivial] %7
1728+
store %9 to [trivial] %6
1729+
dealloc_stack %7
1730+
br bb1
1731+
1732+
bb3:
1733+
%13 = tuple ()
1734+
return %13
1735+
}
1736+
1737+

0 commit comments

Comments
 (0)