Skip to content
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

Tiny improvements in codegen in C backend #7337

Merged
merged 4 commits into from
Feb 11, 2023
Merged

Tiny improvements in codegen in C backend #7337

merged 4 commits into from
Feb 11, 2023

Conversation

steven-johnson
Copy link
Contributor

@steven-johnson steven-johnson commented Feb 10, 2023

(1) Emit true or false instead of (bool)(0ull) etc for bool literals (2) Avoid redundant temporaries in print_cast_expr(), which occur in a small but nonzero number of cases

Basically this means that code currently like

  bool _523 = (bool)(0ull);
  bool _524 = (bool)(_523);
  ...
  foo(_524);

becomes

  foo(false);

...I'm sure this has no output on final object code, but it makes the generated C code less weird to read.

EDIT: (2), do something similar when emitting nullptr constants.

(3), it's 2023, we no longer need to roll our own isnan() and isinf()

(1) Emit `true` or `false` instead of `(bool)(0ull)` etc for bool literals
(2) Avoid redundant temporaries in print_cast_expr(), which occur in a small but nonzero number of cases

Basically this means that code currently like

```
  bool _523 = (bool)(0ull);
  bool _524 = (bool)(_523);
  ...
  foo(_524);
```

becomes

```
  foo(false);
```

...I'm sure this has no output on final object code, but it makes the generated C code less weird to read.
@steven-johnson steven-johnson merged commit 6c5ca8e into main Feb 11, 2023
ardier pushed a commit to ardier/Halide-mutation that referenced this pull request Mar 3, 2024
* Tiny improvements in codegen in C backend

(1) Emit `true` or `false` instead of `(bool)(0ull)` etc for bool literals
(2) Avoid redundant temporaries in print_cast_expr(), which occur in a small but nonzero number of cases

Basically this means that code currently like

```
  bool _523 = (bool)(0ull);
  bool _524 = (bool)(_523);
  ...
  foo(_524);
```

becomes

```
  foo(false);
```

...I'm sure this has no output on final object code, but it makes the generated C code less weird to read.

* Also avoid extra intermediates for typed nullptr

* Also use std::isnan() and std::isinf()

* Update CodeGen_C.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants