OSDN Git Service

[AMDGPU] Add support for TFE/LWE in image intrinsics. 2nd try
authorDavid Stuttard <david.stuttard@amd.com>
Mon, 14 Jan 2019 11:55:24 +0000 (11:55 +0000)
committerDavid Stuttard <david.stuttard@amd.com>
Mon, 14 Jan 2019 11:55:24 +0000 (11:55 +0000)
commit1da08e25141e6c1507d98a63cb4c49f3ba730ac0
treead9bc0d59b74c4cf7b2d512120dc1aabbbb115d5
parenta490b3ede88aedc738297d4a82c0038328c5ccdf
[AMDGPU] Add support for TFE/LWE in image intrinsics. 2nd try

TFE and LWE support requires extra result registers that are written in the
event of a failure in order to detect that failure case.
The specific use-case that initiated these changes is sparse texture support.

This means that if image intrinsics are used with either option turned on, the
programmer must ensure that the return type can contain all of the expected
results. This can result in redundant registers since the vector size must be a
power-of-2.

This change takes roughly 6 parts:
1. Modify the instruction defs in tablegen to add new instruction variants that
can accomodate the extra return values.
2. Updates to lowerImage in SIISelLowering.cpp to accomodate setting TFE or LWE
(where the bulk of the work for these instruction types is now done)
3. Extra verification code to catch cases where intrinsics have been used but
insufficient return registers are used.
4. Modification to the adjustWritemask optimisation to account for TFE/LWE being
enabled (requires extra registers to be maintained for error return value).
5. An extra pass to zero initialize the error value return - this is because if
the error does not occur, the register is not written and thus must be zeroed
before use. Also added a new (on by default) option to ensure ALL return values
are zero-initialized that is required for sparse texture support.
6. Disable the inst_combine optimization in the presence of tfe/lwe (later TODO
for this to re-enable and handle correctly).

There's an additional fix now to avoid a dmask=0

For an image intrinsic with tfe where all result channels except tfe
were unused, I was getting an image instruction with dmask=0 and only a
single vgpr result for tfe. That is incorrect because the hardware
assumes there is at least one vgpr result, plus the one for tfe.

Fixed by forcing dmask to 1, which gives the desired two vgpr result
with tfe in the second one.

The TFE or LWE result is returned from the intrinsics using an aggregate
type. Look in the test code provided to see how this works, but in essence IR
code to invoke the intrinsic looks as follows:

%v = call {<4 x float>,i32} @llvm.amdgcn.image.load.1d.v4f32i32.i32(i32 15,
                                      i32 %s, <8 x i32> %rsrc, i32 1, i32 0)
%v.vec = extractvalue {<4 x float>, i32} %v, 0
%v.err = extractvalue {<4 x float>, i32} %v, 1

This re-submit of the change also includes a slight modification in
SIISelLowering.cpp to work-around a compiler bug for the powerpc_le
platform that caused a buildbot failure on a previous submission.

Differential revision: https://reviews.llvm.org/D48826

Change-Id: If222bc03642e76cf98059a6bef5d5bffeda38dda

Work around for ppcle compiler bug

Change-Id: Ie284cf24b2271215be1b9dc95b485fd15000e32b

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351054 91177308-0d34-0410-b5e6-96231b3b80d8
20 files changed:
include/llvm/IR/IntrinsicsAMDGPU.td
lib/Target/AMDGPU/AMDGPU.h
lib/Target/AMDGPU/AMDGPU.td
lib/Target/AMDGPU/AMDGPUSubtarget.cpp
lib/Target/AMDGPU/AMDGPUSubtarget.h
lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
lib/Target/AMDGPU/CMakeLists.txt
lib/Target/AMDGPU/MIMGInstructions.td
lib/Target/AMDGPU/SIAddIMGInit.cpp [new file with mode: 0644]
lib/Target/AMDGPU/SIISelLowering.cpp
lib/Target/AMDGPU/SIInstrInfo.cpp
lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
lib/Transforms/InstCombine/InstCombineInternal.h
lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
test/CodeGen/AMDGPU/llvm.amdgcn.image.dim.ll
test/CodeGen/AMDGPU/llvm.amdgcn.image.load.a16.d16.ll
test/CodeGen/AMDGPU/llvm.amdgcn.image.load.a16.ll
test/CodeGen/AMDGPU/llvm.amdgcn.image.sample.d16.dim.ll
test/CodeGen/AMDGPU/llvm.amdgcn.image.sample.dim.ll
test/Transforms/InstCombine/AMDGPU/amdgcn-demanded-vector-elts.ll