This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU: Try to select fneg modifier from xor
Needs ReviewPublic

Authored by arsenm on Jan 27 2023, 9:35 AM.

Details

Reviewers
foad
Pierre-vh
sebastian-ne
rampitec
rovka
scott.linder
jmmartinez
Group Reviewers
Restricted Project
Summary

I'm somewhat unhappy with needing to do this. Ideally we could
unconditionally turn all of these into fnegs, but that's going
to confuse other integer patterns that want to look for xor. We
either have to complicate those, or special case this.

Diff Detail

Event Timeline

arsenm created this revision.Jan 27 2023, 9:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 27 2023, 9:35 AM
arsenm requested review of this revision.Jan 27 2023, 9:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 27 2023, 9:35 AM
Herald added a subscriber: wdng. · View Herald Transcript

This does break /llvm/test/CodeGen/AMDGPU/post-ra-soft-clause-dbg-info.ll for reasons I don't understand (the register references go to undef)

Pierre-vh added inline comments.Jan 31 2023, 1:48 AM
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
2568

Can we just do the stripBitcast call earlier? (at Src = In)
That way it simplifies the condition a bit (you can have a if/else if)

2569

Can you add a comment explaining why we need this special-case (like in the commit message) ?

arsenm updated this revision to Diff 505673.Mar 15 2023, 5:57 PM
arsenm marked an inline comment as done.

Rebase and add comment

ping

llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
2568

It would work but adds code in the common case

sebastian-ne added inline comments.Apr 11 2023, 5:24 AM
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
2568

Just guessing into the dark for why post-ra-soft-clause-dbg-info.ll is failing, but it could be because of this stripBitcast.
The code is

v1 = global_load_dword
v1_cast = bitcast i32 v1 to float
debug_value(v1_cast)
v_add_f32 v1_cast, v2

The cast is stripped here (it wasn’t before), so we get

v1 = global_load_dword
v1_cast = bitcast i32 v1 to float
debug_value(v1_cast)
v_add_f32 v1, v2     // <- no cast here anymore

and v1_cast is unused, except for the debug_value.

Dead code elimination removes the bitcast, because it has only debug uses and we get

v1 = global_load_dword
debug_value(<deleted>)
v_add_f32 v1, v2