Skip to content

LICM: fix a wrong tuple type when splitting loads #82012

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
Jun 5, 2025
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
2 changes: 1 addition & 1 deletion lib/SILOptimizer/LoopTransforms/LICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ SingleValueInstruction *LoopTreeOptimization::splitLoad(
}
elements.push_back(elementVal);
}
return builder.createTuple(loc, elements);
return builder.createTuple(loc, loadTy.getObjectType(), elements);
}
auto structTy = loadTy.getStructOrBoundGenericStruct();
assert(structTy && "tuple and struct elements are checked earlier");
Expand Down
31 changes: 31 additions & 0 deletions test/SILOptimizer/licm.sil
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ struct S {
var s: String
}

struct Pair {
var t: (a: Int, b: Int)
}

// globalArray
sil_global @globalArray : $Storage

Expand Down Expand Up @@ -1704,3 +1708,30 @@ bb4(%14 : @reborrow $S):
return %r
}

// Just check that LICM doesn't produce invalid SIL because of a tuple type mismatch.
// CHECK-LABEL: sil [ossa] @split_load_of_labeld_tuples :
// CHECK-LABEL: } // end sil function 'split_load_of_labeld_tuples'
sil [ossa] @split_load_of_labeld_tuples : $@convention(thin) (@inout Pair, Int) -> () {
bb0(%0 : $*Pair, %1 : $Int):
br bb1

bb1:
cond_br undef, bb3, bb2

bb2:
%4 = load [trivial] %0
%5 = struct_element_addr %0, #Pair.t
%6 = tuple_element_addr %5, 0
%7 = alloc_stack $Int
store %1 to [trivial] %7
%9 = load [trivial] %7
store %9 to [trivial] %6
dealloc_stack %7
br bb1

bb3:
%13 = tuple ()
return %13
}