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
@@ -61,10 +61,6 @@ fn Main() {
// CHECK:STDOUT: %.1: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.2: type = tuple_type () [template]
// CHECK:STDOUT: %.3: i32 = int_literal 0 [template]
// CHECK:STDOUT: %.4: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.5: i32 = int_literal 0 [template]
// CHECK:STDOUT: %.6: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.7: i32 = int_literal 0 [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
@@ -97,18 +93,18 @@ fn Main() {
// CHECK:STDOUT: %.loc18_7: init () = call %Run0.ref.loc18(<invalid>)
// CHECK:STDOUT: %Run0.ref.loc25: <function> = name_ref Run0, file.%Run0 [template = file.%Run0]
// CHECK:STDOUT: %.loc25_8: i32 = int_literal 0 [template = constants.%.3]
// CHECK:STDOUT: %.loc25_11: i32 = int_literal 1 [template = constants.%.4]
// CHECK:STDOUT: %.loc25_11: i32 = int_literal 1 [template = constants.%.1]
// CHECK:STDOUT: %.loc25_7: init () = call %Run0.ref.loc25(<invalid>)
// CHECK:STDOUT: %Run1.ref.loc33: <function> = name_ref Run1, file.%Run1 [template = file.%Run1]
// CHECK:STDOUT: %.loc33: init () = call %Run1.ref.loc33(<invalid>)
// CHECK:STDOUT: %Run1.ref.loc40: <function> = name_ref Run1, file.%Run1 [template = file.%Run1]
// CHECK:STDOUT: %.loc40_8: i32 = int_literal 0 [template = constants.%.5]
// CHECK:STDOUT: %.loc40_11: i32 = int_literal 1 [template = constants.%.6]
// CHECK:STDOUT: %.loc40_8: i32 = int_literal 0 [template = constants.%.3]
// CHECK:STDOUT: %.loc40_11: i32 = int_literal 1 [template = constants.%.1]
// CHECK:STDOUT: %.loc40_7: init () = call %Run1.ref.loc40(<invalid>)
// CHECK:STDOUT: %Run2.ref.loc48: <function> = name_ref Run2, file.%Run2 [template = file.%Run2]
// CHECK:STDOUT: %.loc48: init () = call %Run2.ref.loc48(<invalid>)
// CHECK:STDOUT: %Run2.ref.loc55: <function> = name_ref Run2, file.%Run2 [template = file.%Run2]
// CHECK:STDOUT: %.loc55_8: i32 = int_literal 0 [template = constants.%.7]
// CHECK:STDOUT: %.loc55_8: i32 = int_literal 0 [template = constants.%.3]
// CHECK:STDOUT: %.loc55_7: init () = call %Run2.ref.loc55(<invalid>)
// CHECK:STDOUT: return
// CHECK:STDOUT: }
@@ -16,7 +16,6 @@ fn Main() {
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.2: type = tuple_type () [template]
// CHECK:STDOUT: %.3: i32 = int_literal 1 [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
@@ -36,7 +35,7 @@ fn Main() {
// CHECK:STDOUT: %.loc10_7: i32 = int_literal 1 [template = constants.%.1]
// CHECK:STDOUT: %.loc10_6: init () = call %Foo.ref.loc10(%.loc10_7)
// CHECK:STDOUT: %Foo.ref.loc11: <function> = name_ref Foo, file.%Foo [template = file.%Foo]
// CHECK:STDOUT: %.loc11_7: i32 = int_literal 1 [template = constants.%.3]
// CHECK:STDOUT: %.loc11_7: i32 = int_literal 1 [template = constants.%.1]
// CHECK:STDOUT: %.loc11_6: init () = call %Foo.ref.loc11(%.loc11_7)
// CHECK:STDOUT: return
// CHECK:STDOUT: }
@@ -17,8 +17,6 @@ fn Main() {
// CHECK:STDOUT: %.1: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.2: i32 = int_literal 2 [template]
// CHECK:STDOUT: %.3: type = tuple_type () [template]
// CHECK:STDOUT: %.4: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.5: i32 = int_literal 2 [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
@@ -39,8 +37,8 @@ fn Main() {
// CHECK:STDOUT: %.loc10_10: i32 = int_literal 2 [template = constants.%.2]
// CHECK:STDOUT: %.loc10_6: init () = call %Foo.ref.loc10(%.loc10_7, %.loc10_10)
// CHECK:STDOUT: %Foo.ref.loc11: <function> = name_ref Foo, file.%Foo [template = file.%Foo]
// CHECK:STDOUT: %.loc11_7: i32 = int_literal 1 [template = constants.%.4]
// CHECK:STDOUT: %.loc11_10: i32 = int_literal 2 [template = constants.%.5]
// CHECK:STDOUT: %.loc11_7: i32 = int_literal 1 [template = constants.%.1]
// CHECK:STDOUT: %.loc11_10: i32 = int_literal 2 [template = constants.%.2]
// CHECK:STDOUT: %.loc11_6: init () = call %Foo.ref.loc11(%.loc11_7, %.loc11_10)
// CHECK:STDOUT: return
// CHECK:STDOUT: }