Skip to content

Commit e3f8048

Browse files
Merge pull request #82700 from nate-chandler/cherrypick/release/6.2/rdar154652254
6.2: [CSE] Fix combine of type_value.
2 parents 40c4f3c + b730144 commit e3f8048

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

lib/SILOptimizer/Transforms/CSE.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,7 @@ class HashVisitor : public SILInstructionVisitor<HashVisitor, llvm::hash_code> {
520520
}
521521

522522
hash_code visitTypeValueInst(TypeValueInst *X) {
523-
OperandValueArrayRef Operands(X->getAllOperands());
524-
return llvm::hash_combine(
525-
X->getKind(), X->getType(),
526-
llvm::hash_combine_range(Operands.begin(), Operands.end()));
523+
return llvm::hash_combine(X->getKind(), X->getType(), X->getParamType());
527524
}
528525
};
529526
} // end anonymous namespace
@@ -568,6 +565,13 @@ bool llvm::DenseMapInfo<SimpleValue>::isEqual(SimpleValue LHS,
568565

569566
return true;
570567
}
568+
auto *ltvi = dyn_cast<TypeValueInst>(LHSI);
569+
auto *rtvi = dyn_cast<TypeValueInst>(RHSI);
570+
if (ltvi && rtvi) {
571+
if (ltvi->getType() != rtvi->getType())
572+
return false;
573+
return ltvi->getParamType() == rtvi->getParamType();
574+
}
571575
auto opCmp = [&](const Operand *op1, const Operand *op2) -> bool {
572576
if (op1 == op2)
573577
return true;

test/SILOptimizer/cse.sil

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,4 +1447,3 @@ bb0:
14471447
%r1 = tuple ()
14481448
return %r1 : $()
14491449
}
1450-

test/SILOptimizer/cse_ossa.sil

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,3 +1351,16 @@ bb0(%0 : $*InlineArray<N, Int>, %1 : $Int):
13511351
return %14
13521352
}
13531353

1354+
struct Pair<let x: Int, let y: Int> {}
1355+
// CHECK-LABEL: sil [ossa] @dont_cse_different_type_values : {{.*}} {
1356+
// CHECK: type_value
1357+
// CHECK: type_value
1358+
// CHECK-LABEL: } // end sil function 'dont_cse_different_type_values'
1359+
sil [ossa] @dont_cse_different_type_values : $@convention(method) <let x : Int, let y : Int> (Pair<x, y>) -> (Int, Int) {
1360+
[global: ]
1361+
bb0(%0 : $Pair<x, y>):
1362+
%2 = type_value $Int for x
1363+
%3 = type_value $Int for y
1364+
%4 = tuple (%2, %3)
1365+
return %4
1366+
}

0 commit comments

Comments
 (0)