This allows for bitcast conversion to roundtrip.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Should we also update verifier to allow bitcasts to have same src and dst type? Is this allowed in spirv?
upd: original issue was failing with "result type must be different from operand type" but I cannot even find where it is checked.
It's not allowed: https://registry.khronos.org/SPIR-V/specs/1.2/SPIRV.html#OpBitcast
Operand must have a type of OpTypePointer, or a scalar or vector of numerical-type. It must be a different type than Result Type.
I'm ok to merge it as is to fix the bug, but we are basically abusing the fact the folder will run immediately after pattern, 'fixing' invalid IR that was produced.
Good point. Stamped without thinking through this. Maybe we can just change the folder to look for
%0 = spirv.Bitcast %a : <typea> to <typeb> %1 = spirv.Bitcast %b : <typeb> to <typec>
and then fold to either
%0 = spirv.BItcast %a : <typea> to <typec>
or just
%a
if <typea> == <typeb>.
Marking as request changes for now.
mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp | ||
---|---|---|
125 | It is only checks for limited depth, you can do smth like this to check into arbitrary deoth Value current = getOperand(); while (auto parent = current.getDefiningOp<BitcastOp>()) { auto parentSource = parent.getOperand(); if (parentSource.getType() == getType()) return parentSource; current = parentSource; } |
mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp | ||
---|---|---|
125 | Wait, nevermind, it will still check for arbitrary depth after multiple iterations, right? |
mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp | ||
---|---|---|
125 | It works with longer chains because the innermost argument is always pushed through |
It is only checks for limited depth, you can do smth like this to check into arbitrary deoth