[llvm] [DAG] Fixing the non-optimal code with the following: `select i1 %0, float 1.0, float 0.0`. (PR #107732)

Phoebe Wang via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 8 00:06:20 PDT 2024


phoebewang wrote:

> https://github.com/llvm/llvm-project/blob/caebb4562ce634a22f7b13480b19cffc2a6a6730/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L17953-L17959
> 
> It seems that when applying this patch, we are switching back and forth between `select` and `uint_to_fp`.
> 
> ```
>   // fold (uint_to_fp (setcc x, y, cc)) -> (select (setcc x, y, cc), 1.0, 0.0)
>   if (N0.getOpcode() == ISD::SETCC && !VT.isVector() &&
>       (!LegalOperations || TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT))) {
>     SDLoc DL(N);
>     return DAG.getSelect(DL, VT, N0, DAG.getConstantFP(1.0, DL, VT),
>                          DAG.getConstantFP(0.0, DL, VT));
>   }
> ```

How about doing it in `lowerSELECT`? It looks like RISCV does it in this way without infinite loop:
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/RISCV/RISCVISelLowering.cpp#L8002

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


More information about the llvm-commits mailing list