Deduplicate and canonicalize all constants. (#3611)

Rather than producing multiple constants with the same value, fold all
instances of a given constant to the same constant instruction.

A future PR will use this to replace the current type canonicalization
system.
This commit is contained in:
Richard Smith
2024-01-18 21:42:19 +00:00
committed by GitHub
parent 62db3e9ad0
commit 29c294880d
142 changed files with 1603 additions and 1185 deletions
+8 -10
View File
@@ -20,12 +20,10 @@ fn G() -> i32 {
// CHECK:STDOUT: %.3: type = ptr_type [i32; 3] [template]
// CHECK:STDOUT: %.4: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.5: i32 = int_literal 2 [template]
// CHECK:STDOUT: %.6: i32 = int_literal 3 [template]
// CHECK:STDOUT: %.7: type = tuple_type (i32, i32, i32) [template]
// CHECK:STDOUT: %.6: type = tuple_type (i32, i32, i32) [template]
// CHECK:STDOUT: %.7: i32 = int_literal 0 [template]
// CHECK:STDOUT: %.8: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.9: i32 = int_literal 0 [template]
// CHECK:STDOUT: %.10: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.11: i32 = int_literal 2 [template]
// CHECK:STDOUT: %.9: i32 = int_literal 2 [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
@@ -49,17 +47,17 @@ fn G() -> i32 {
// CHECK:STDOUT: %F.ref: <function> = name_ref F, file.%F [template = file.%F]
// CHECK:STDOUT: %.loc12_13: i32 = int_literal 1 [template = constants.%.4]
// CHECK:STDOUT: %.loc12_16: i32 = int_literal 2 [template = constants.%.5]
// CHECK:STDOUT: %.loc12_19: i32 = int_literal 3 [template = constants.%.6]
// CHECK:STDOUT: %.loc12_19: i32 = int_literal 3 [template = constants.%.1]
// CHECK:STDOUT: %.loc12_20.1: (i32, i32, i32) = tuple_literal (%.loc12_13, %.loc12_16, %.loc12_19)
// CHECK:STDOUT: %.loc12_23: i32 = int_literal 1 [template = constants.%.8]
// CHECK:STDOUT: %.loc12_23: i32 = int_literal 1 [template = constants.%.4]
// CHECK:STDOUT: %.loc12_20.2: ref [i32; 3] = temporary_storage
// CHECK:STDOUT: %.loc12_20.3: i32 = int_literal 0 [template = constants.%.9]
// CHECK:STDOUT: %.loc12_20.3: i32 = int_literal 0 [template = constants.%.7]
// CHECK:STDOUT: %.loc12_20.4: ref i32 = array_index %.loc12_20.2, %.loc12_20.3
// CHECK:STDOUT: %.loc12_20.5: init i32 = initialize_from %.loc12_13 to %.loc12_20.4
// CHECK:STDOUT: %.loc12_20.6: i32 = int_literal 1 [template = constants.%.10]
// CHECK:STDOUT: %.loc12_20.6: i32 = int_literal 1 [template = constants.%.8]
// CHECK:STDOUT: %.loc12_20.7: ref i32 = array_index %.loc12_20.2, %.loc12_20.6
// CHECK:STDOUT: %.loc12_20.8: init i32 = initialize_from %.loc12_16 to %.loc12_20.7
// CHECK:STDOUT: %.loc12_20.9: i32 = int_literal 2 [template = constants.%.11]
// CHECK:STDOUT: %.loc12_20.9: i32 = int_literal 2 [template = constants.%.9]
// CHECK:STDOUT: %.loc12_20.10: ref i32 = array_index %.loc12_20.2, %.loc12_20.9
// CHECK:STDOUT: %.loc12_20.11: init i32 = initialize_from %.loc12_19 to %.loc12_20.10
// CHECK:STDOUT: %.loc12_20.12: init [i32; 3] = array_init (%.loc12_20.5, %.loc12_20.8, %.loc12_20.11) to %.loc12_20.2