[llvm] [AMDGPU] Fold fneg into select source modifiers (PR #201426)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 9 21:17:35 PDT 2026
lijinpei-amd wrote:
> > Add shouldFoldFNegIntoSelect to gate the fold between:
> > ```
> > fneg(select) <--> select(fneg, fneg)
> > ```
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > * f32, choose select(fneg, fneg).
> > * f64, choose fneg(select).
>
> But for f64 we also want select(fneg, fneg), right? At least the final codegen we want is two v_cndmask_b32 where the one for the high halves uses the neg modifier.
For f64, after this patch, select(fneg, fneg) will be 'canonicalized' into `fneg(select)`, and same equal optimal codegen.
The reason do do the 'canonicalization' is `fneg(select)` can be matched by this combine https://github.com/llvm/llvm-project/blob/4143eee75d13ce3a10fbf81b56220e1e13b915f1/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp#L5483 , while the matching the `select(fneg, fneg)` with all the `bitcase`, `build_vector` is ...... a little bit hard.
As Matt mentioned https://github.com/llvm/llvm-project/issues/171724#issuecomment-4658618992 , (at least for recent rdna/cdna which has many fp64 intructions) but I think that would be substantial change at least for tests.
https://github.com/llvm/llvm-project/pull/201426
More information about the llvm-commits
mailing list