[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 07:47:58 PDT 2024
goldsteinn wrote:
> ```
> define i32 @before(i1 %cond) {
> %sel = select i1 %cond, i32 32, i32 0
> call void @use(i32 %sel)
> %ret = or disjoint i32 %sel, 16
> ret i32 %ret
> }
>
> define i32 @after(i1 %cond) {
> %sel = select i1 %cond, i32 32, i32 0
> call void @use(i32 %sel)
> %ret = select i1 %cond, i32 48, i32 16
> ret i32 %ret
> }
> ```
>
> I don't think the latter form is better than the former. Do we need the one-use check?
Yeah, Although I would would think this is somewhat instruction dependent.
I.e `div`/`mul`, I would probably prefer the constant folded select, `or`/`and`,
the logic op.
Ill update with a flag for if we can accept more than 1 use.
https://github.com/llvm/llvm-project/pull/84696
More information about the llvm-commits
mailing list