Skip to content

clang cannot optimize fraction (c * a / b) when c is a power of 2 under the condition that other fraction (a / d) implies #72045

@k-arrows

Description

@k-arrows

Consider the following functions.
https://godbolt.org/z/KxdWKofjd

int test2(int a) {
  if (a / 5)
    return 0;
  else
    return (2 * a / 9);
}

int test3(int a) {
  if (a / 5)
    return 0;
  else
    return (3 * a / 13);
}

int test4(int a) {
  if (a / 5)
    return 0;
  else
    return (4 * a / 17);
}

int test5(int a) {
  if (a / 5)
    return 0;
  else
    return (5 * a / 21);
}

int test6(int a) {
  if (a / 5)
    return 0;
  else
    return (6 * a / 25);
}

int test7(int a) {
  if (a / 5)
    return 0;
  else
    return (7 * a / 29);
}

int test8(int a) {
  if (a / 5)
    return 0;
  else
    return (8 * a / 33);
}

All of these functions can be optimized (to the function which returns zero), but Clang cannot optimize test2, test4, and test8.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions