Issue 171724
Summary AMDGPU: Select of double with fneg inputs does not use source modifiers with v_cndmask_b32
Labels backend:AMDGPU, missed-optimization
Assignees
Reporter arsenm
    https://godbolt.org/z/n9GYarEof

Select of f64 with fneg/fabs inputs does not produce the ideal output. It does not make use of source modifiers, and we get bit instructions:

```
; Missed source modifiers on the high half
;	v_xor_b32_e32 v2, 0x80000000, v2
;	v_xor_b32_e32 v4, 0x80000000, v4
;	v_cmp_eq_u32_e32 vcc, 0, v0
;	v_cndmask_b32_e32 v0, v1, v3, vcc
;	v_cndmask_b32_e32 v1, v2, v4, vcc
define double @select_f64_fneg(i32 %cond, double %arg, double %arg1) {
bb:
  %neg.0 = fneg double %arg
  %neg.1 = fneg double %arg1
  %cmp = icmp eq i32 %cond, 0
  %select = select i1 %cmp, double %neg.1, double %neg.0
  ret double %select
}
```

Oddly if the fneg is pulled out of the select, we get the ideal result, with the fneg pushed back into the select:
```
; Does produce the ideal result
;	v_cmp_eq_u32_e32 vcc, 0, v0
;	v_cndmask_b32_e32 v0, v3, v1, vcc
;	v_cndmask_b32_e64 v1, -v4, -v2, vcc
define double @fneg_select_f64(i32 %cond, double %arg, double %arg1) {
bb:
  %cmp = icmp eq i32 %cond, 0
  %select = select i1 %cmp, double %arg, double %arg1
  %neg.select = fneg double %select
  ret double %neg.select
}
```






_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to