[llvm] [AMDGPU] Improve codegen for copysign(x, fneg(y)) (PR #207178)

Madhur Kumar via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 16 03:23:40 PDT 2026


================
@@ -2938,11 +2954,31 @@ def : AMDGPUPat <
   (S_AND_B32 (S_MOV_B32 (i32 0x80000000)), $src1)
 >;
 
+def : AMDGPUPat <
+  (DivergentBinFrag<fcopysign> (f32 fpimm_zero), (fneg f32:$src1)),
+  (V_BFI_B32_e64 VGPR_32:$src1, (i32 0), (S_MOV_B32 (i32 0x80000000)))
+>;
+
 def : AMDGPUPat <
   (fcopysign (f32 fpimm_pos_zero), (f32 VGPR_32:$src1)),
   (V_AND_B32_e32 (S_MOV_B32 (i32 0x80000000)), $src1)
 >;
 
+def : AMDGPUPat <
+  (DivergentBinFrag<and> (extractelt (v2i32 (bitconvert (f64 (fneg f64:$src1)))), (i32 1)),
+       (i32 -2147483648)),
+  (V_BFI_B32_e64 (i32 (EXTRACT_SUBREG VReg_64:$src1, sub1)),
+                 (i32 0), (S_MOV_B32 (i32 0x80000000)))
+>;
+
+
+def : AMDGPUPat <
+  (DivergentBinFrag<and> (i32 (bitconvert (extractelt (v2f32 (bitconvert (fneg f64:$src1))), (i32 1)))),
----------------
MadhurKumar004 wrote:

This is the selectionDAG we get after legalizing v2f64 into scalar f64. While trying to extract the sign bit from f64 , compiler does 'Bitcast f64 -> v2f32' , extract the index 1(higher 32 bit word). and AND with 0x80000000

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


More information about the llvm-commits mailing list