Closed ruiminzhao closed 9 months ago
I'll take a look, but how is it possible for you to end up with such code in the first place? What's the corresponding SPIR-V code that would cause you to load or store a buffer pointer in a buffer?
Another idea is to teach the visitor infrastructure about potentially having to re-visit newly inserted instructions. Basically, TypeLowering::visitLoad would return some indication that the code which has just been created by it has to be visited again. This would mean that visitor functions can return some
llvm_dialects::VisitResult
value.
Besides revisiting newly inserted instructions, we also need a way to notify other visitors stop visiting the old instruction which was just being lowered. For this case, the TypeLowering::visitLoad
needs a way to notify BufferOpLowering
: the load instruction has been lowered and marked for deletion, please don't visit/lower it again. I am not sure whether this can be achieved somehow and whether this is doable.
Close this PR and new PR submitted which only added the assertion in https://github.com/GPUOpen-Drivers/llpc/pull/2881.
Any case meet this pattern: "load ptr(7), ptr(7)", I will reopen this PR for fix.
Thanks.
Issue Description
There are issue when lowering on load instruction which both result type and pointer operand type are fat buffer pointer.
An example IR:
Currently, as %10 and %11 which operand address space are 7, so they are all be added into postVisitLoad list. The 1st issue is when call replaceLoadStore for %10, it will be lowered into i160 not <4xi32, i32> finally. Then call replaceLoadStore for %11, it will be crashed when call m_typeLowering.getValue(pointerOperand).
The 2nd issue is TypeLowering.visitLoad will handle on %10 firstly, then BufferOp.postVisitLoad will handle on %10 again as the pointer operand address space is 7(fat_buffer_pointer), then %10 will be added into m_instructionsToErase again, then it will be crashed when erase this load instruction.
Issue Solution:
Now I have moved the instructions formatted "load ptr7, ptr7" from typeLowering.visitLoad into PatchBufferOp.postVisitLoad, but I'm not sure this will be correct for other parts such as CPS, which doesn't have postVisitLoad function to handle operand = ptr<7> cases.
Any better solution will be appreciated.