Skip to content

AND with == 0 and OR with != 0 #68799

Open
@k-arrows

Description

@k-arrows

It was difficult to title the issue. Feel free to modify it appropriately.

Consider the following functions:

bool f_and(int x,int y)
{
  bool a = x == 0;
  bool b = y == 0;
  bool t = a & b;
  return t & !a;
}

bool f_or(int x,int y)
{
  bool a = x != 0;
  bool b = y != 0;
  bool t = a | b;
  return t | !a;
}

The function f_and can be optimized to 0, and f_or can be optimized to 1.

https://godbolt.org/z/nWq194nz9
https://alive2.llvm.org/ce/z/PPCfP9

FYI (original issue)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111542

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions