Skip to content

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 requested a review from vksnk February 10, 2023 23:02
@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