Skip to content

Commit

Permalink
AMDGPU: Lower addrspacecast on gfx6
Browse files Browse the repository at this point in the history
Fixes inconsistent handling of constant-32bit case. Turns out we can
lower all the casts just fine, it's just accessing the flat results
that's a problem.
  • Loading branch information
arsenm committed Dec 18, 2022
1 parent 6f5cdc9 commit 9d6003c
Show file tree
Hide file tree
Showing 4 changed files with 352 additions and 471 deletions.
3 changes: 0 additions & 3 deletions llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1980,9 +1980,6 @@ bool AMDGPULegalizerInfo::legalizeAddrSpaceCast(
if (DestAS == AMDGPUAS::FLAT_ADDRESS &&
(SrcAS == AMDGPUAS::LOCAL_ADDRESS ||
SrcAS == AMDGPUAS::PRIVATE_ADDRESS)) {
if (!ST.hasFlatAddressSpace())
return false;

Register ApertureReg = getSegmentAperture(SrcAS, MRI, B);
if (!ApertureReg.isValid())
return false;
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/AMDGPU/SIISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ SITargetLowering::SITargetLowering(const TargetMachine &TM,
setOperationAction(ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS, {MVT::i32, MVT::i64},
Expand);

if (Subtarget->hasFlatAddressSpace())
setOperationAction(ISD::ADDRSPACECAST, {MVT::i32, MVT::i64}, Custom);
setOperationAction(ISD::ADDRSPACECAST, {MVT::i32, MVT::i64}, Custom);

setOperationAction(ISD::BITREVERSE, {MVT::i32, MVT::i64}, Legal);

Expand Down
Loading

1 comment on commit 9d6003c

@nikic
Copy link
Contributor

@nikic nikic commented on 9d6003c Dec 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the expensive checks build:

# After Legalizer
# Machine code for function constant32bit_to_flat_addrspacecast_0: IsSSA, TracksLiveness, Legalized
bb.1 (%ir-block.0):
  liveins: $vgpr0
  %0:_(p6) = COPY $vgpr0
  %4:_(p6) = G_CONSTANT i32 0
  %2:_(s32) = G_BITCAST %0:_(p6)
  %3:_(s32) = G_BITCAST %4:_(p6)
  $vgpr0 = COPY %2:_(s32)
  $vgpr1 = COPY %3:_(s32)
  SI_RETURN implicit $vgpr0, implicit $vgpr1
# End machine code for function constant32bit_to_flat_addrspacecast_0.
*** Bad machine code: bitcast cannot convert between pointers and other types ***
- function:    constant32bit_to_flat_addrspacecast_0
- basic block: %bb.1  (0x7a6ad40)
- instruction: %2:_(s32) = G_BITCAST %0:_(p6)
*** Bad machine code: bitcast cannot convert between pointers and other types ***
- function:    constant32bit_to_flat_addrspacecast_0
- basic block: %bb.1  (0x7a6ad40)
- instruction: %3:_(s32) = G_BITCAST %4:_(p6)
LLVM ERROR: Found 2 machine code errors.

Please sign in to comment.