Skip to content

Simplifications of max/min (a & c0, a & c1) under (c0 & c1) == c1/c0 #65833

@k-arrows

Description

@k-arrows

The following two functions can be simplified, and this is motivated from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109878.

#include<iostream>

unsigned foo(unsigned a, unsigned c0, unsigned c1)
{
   return ((c0 & c1) == c1) ? std::max(a & c0, a & c1) : (a & c0);
}

unsigned bar(unsigned a, unsigned c0, unsigned c1)
{
   return ((c0 & c1) == c0) ? std::min(a & c0, a & c1) : (a & c0);
}

Alive2:
https://alive2.llvm.org/ce/z/kQrReA
https://alive2.llvm.org/ce/z/UQay5M

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions