diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp @@ -117,22 +117,22 @@ //===----------------------------------------------------------------------===// OpFoldResult spirv::BitcastOp::fold(ArrayRef /*operands*/) { - Value arg = getOperand(); - if (getType() == arg.getType()) - return arg; + Value curInput = getOperand(); + if (getType() == curInput.getType()) + return curInput; // Look through nested bitcasts. - if (auto bitcast = arg.getDefiningOp()) { - Value nestedArg = bitcast.getOperand(); - if (nestedArg.getType() == getType()) - return nestedArg; + if (auto prevCast = curInput.getDefiningOp()) { + Value prevInput = prevCast.getOperand(); + if (prevInput.getType() == getType()) + return prevInput; - getOperandMutable().assign(nestedArg); + getOperandMutable().assign(prevInput); return getResult(); } // TODO(kuhar): Consider constant-folding the operand attribute. - return getResult(); + return {}; } //===----------------------------------------------------------------------===//