Skip to content

Remove Cifthenelse #3859

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mshinwell
Copy link
Collaborator

This is to bring the Cmm language further in line with Flambda 2.

I think this should be ok, but will look at the generated code. Two problems might be:

  • if instruction selection failed to recognise the pattern generated by Cmm_helpers.ifthenelse, what will happen? This should be fine if the results of e.g. Iinttest are in {0, 1}, but is that guaranteed?
  • if an existing Cswitch on {0, 1} gets caught by the new pattern in instruction selection, will the code be worse? It's unclear such a switch would ever be generated anyway (see To_cmm_expr.switch).

@mshinwell mshinwell added the cmm Cmm language / helpers changes label Apr 15, 2025
@mshinwell mshinwell changed the title Remove cifthenelse Remove Cifthenelse Apr 15, 2025
@mshinwell
Copy link
Collaborator Author

mshinwell commented Apr 15, 2025

This is based on #3855
update: not any more

@mshinwell mshinwell force-pushed the remove-cifthenelse branch from 73291b8 to 90bcf2a Compare April 15, 2025 13:43
@mshinwell
Copy link
Collaborator Author

Ah but the first bullet point isn't quite right: the "test"s won't be generated unless we go through the if-then-else instruction selection code. So we would go via select_arith_comp and it should be fine.

@mshinwell mshinwell force-pushed the remove-cifthenelse branch 2 times, most recently from 8f6f4ae to 1bcc5b7 Compare April 16, 2025 11:45
@mshinwell mshinwell force-pushed the remove-cifthenelse branch from 1bcc5b7 to 08f8ff9 Compare April 16, 2025 14:06
@@ -871,6 +871,11 @@ let[@inline] get_const = function
| Cconst_natint (i, _) -> Some i
| _ -> None

let ifthenelse (cond, then_dbg, then_, else_dbg, else_, dbg) =
(* This case is matched on in [Cfg_selection] *)
let cond = tag_int (Cop (Ccmpi Cne, [cond; Cconst_int (1, dbg)], dbg)) dbg in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need tag_int around this expression?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmm Cmm language / helpers changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants