[llvm] [InstCombine] Use the select condition to try to constant fold binops into select (PR #84696)

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 08:54:51 PDT 2024


goldsteinn wrote:

> > the right approach would be teach the backend to undo this
> 
> TBH it is hard to undo the transform :(
> 
> IIRC the backend doesn't even reuse constants that have been materialized. Related issues: #80880 #71389 #68712

Oh I overlooked the fact you would need to iterate the use list of `cond`.
Yeah it might be a bit tricky, though finding functions like and/xor/or/add/sub...
for f(true_arm0) -> f(true_arm1) and f(false_arm0) -> f(false_arm1) isn't so bad.

Ill drop now, if I make a patch to fix this up in backend, ill update.

A de-canonicalizing pre backend pass might be useful for something like this.
Its a bit of a pain that in instcombine we are constantly weighing whats easier
to analyze w/ what gets good codegen.

Another example might be we emit  `ctpop(x) <= 1` instead of `ctpop(x) == 1`.

https://github.com/llvm/llvm-project/pull/84696


More information about the llvm-commits mailing list