Skip to content

Commit

Permalink
Limit CSE of integer constants
Browse files Browse the repository at this point in the history
Never do CSE for constants that fit in 32 bits signed.

Do it only for constants that do not fit, and only on some 64-bit targets
where the code generated for Iconst_int can be costly (ARM64, POWER, RISC-V).
  • Loading branch information
xavierleroy committed Sep 6, 2021
1 parent cd105d9 commit 29d3fc7
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 8 deletions.
5 changes: 0 additions & 5 deletions asmcomp/arm/CSE.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ method! class_of_operation op =
| Ispecific _ -> Op_pure
| _ -> super#class_of_operation op

method! is_cheap_operation op =
match op with
| Iconst_int n -> n <= 255n && n >= 0n
| _ -> false

end

let fundecl f =
Expand Down
2 changes: 1 addition & 1 deletion asmcomp/arm64/CSE.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ method! class_of_operation op =

method! is_cheap_operation op =
match op with
| Iconst_int n -> n <= 65535n && n >= 0n
| Iconst_int n -> n <= 0x7FFF_FFFFn && n >= -0x8000_0000n
| _ -> false

end
Expand Down
2 changes: 1 addition & 1 deletion asmcomp/power/CSE.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ method! class_of_operation op =

method! is_cheap_operation op =
match op with
| Iconst_int n -> n <= 32767n && n >= -32768n
| Iconst_int n -> n <= 0x7FFF_FFFFn && n >= -0x8000_0000n
| _ -> false

end
Expand Down
2 changes: 1 addition & 1 deletion asmcomp/riscv/CSE.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ method! class_of_operation op =

method! is_cheap_operation op =
match op with
| Iconst_int n -> n <= 0x7FFn && n >= -0x800n
| Iconst_int n -> n <= 0x7FFF_FFFFn && n >= -0x8000_0000n
| _ -> false

end
Expand Down

0 comments on commit 29d3fc7

Please sign in to comment.