[PATCH] D94089: [Reassociate] move check to ignore boolean expressions before canonicalizing binary operands

Marius Hillenbrand via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 5 09:16:43 PST 2021


mhillenbrand added a comment.

@lebedev.ri No, I do not see differences in observable side-effects. Though, runtime differs significantly depending on the order of evaluation. Thus, "intent" would be out-of-band information that the programmer has about the likelihood of  each of the terms being true, and placing the most-likely term first, while that cannot be derived from the source by the compiler.

In the example

  if (ab > de || ac > df || bc > cd)
        return 0;

the programmer may know that (ab > de) is more commonly true than (ac >df) and thus place the former check first. With short-circuited evaluation strictly in the order of the source code, the resulting code would execute fewer comparisons and run faster, and vice versa.

@fhahn I will add a test (seeking feedback whether this actually makes sense with this initial submission).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94089/new/

https://reviews.llvm.org/D94089



More information about the llvm-commits mailing list