Skip to content

Commit 86a59d9

Browse files
andrey-golubevtstellar
authored andcommitted
[mlir][LLVM] Use int32_t to indirectly construct GEPArg (llvm#79562)
GEPArg can only be constructed from int32_t and mlir::Value. Explicitly cast other types (e.g. unsigned, size_t) to int32_t to avoid narrowing conversion warnings on MSVC. Some recent examples of such are: ``` mlir\lib\Dialect\LLVMIR\Transforms\TypeConsistency.cpp: error C2398: Element '1': conversion from 'size_t' to 'T' requires a narrowing conversion with [ T=mlir::LLVM::GEPArg ] mlir\lib\Dialect\LLVMIR\Transforms\TypeConsistency.cpp: error C2398: Element '1': conversion from 'unsigned int' to 'T' requires a narrowing conversion with [ T=mlir::LLVM::GEPArg ] ``` Co-authored-by: Nikita Kudriavtsev <nikita.kudriavtsev@intel.com> (cherry picked from commit 89cd345)
1 parent ec9077b commit 86a59d9

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,8 @@ LogicalResult GPUPrintfOpToVPrintfLowering::matchAndRewrite(
529529
/*alignment=*/0);
530530
for (auto [index, arg] : llvm::enumerate(args)) {
531531
Value ptr = rewriter.create<LLVM::GEPOp>(
532-
loc, ptrType, structType, tempAlloc, ArrayRef<LLVM::GEPArg>{0, index});
532+
loc, ptrType, structType, tempAlloc,
533+
ArrayRef<LLVM::GEPArg>{0, static_cast<int32_t>(index)});
533534
rewriter.create<LLVM::StoreOp>(loc, arg, ptr);
534535
}
535536
std::array<Value, 2> printfArgs = {stringStart, tempAlloc};

mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1041,13 +1041,14 @@ Value ConvertLaunchFuncOpToGpuRuntimeCallPattern::generateParamsArray(
10411041
auto arrayPtr = builder.create<LLVM::AllocaOp>(
10421042
loc, llvmPointerType, llvmPointerType, arraySize, /*alignment=*/0);
10431043
for (const auto &en : llvm::enumerate(arguments)) {
1044+
const auto index = static_cast<int32_t>(en.index());
10441045
Value fieldPtr =
10451046
builder.create<LLVM::GEPOp>(loc, llvmPointerType, structType, structPtr,
1046-
ArrayRef<LLVM::GEPArg>{0, en.index()});
1047+
ArrayRef<LLVM::GEPArg>{0, index});
10471048
builder.create<LLVM::StoreOp>(loc, en.value(), fieldPtr);
1048-
auto elementPtr = builder.create<LLVM::GEPOp>(
1049-
loc, llvmPointerType, llvmPointerType, arrayPtr,
1050-
ArrayRef<LLVM::GEPArg>{en.index()});
1049+
auto elementPtr =
1050+
builder.create<LLVM::GEPOp>(loc, llvmPointerType, llvmPointerType,
1051+
arrayPtr, ArrayRef<LLVM::GEPArg>{index});
10511052
builder.create<LLVM::StoreOp>(loc, fieldPtr, elementPtr);
10521053
}
10531054
return arrayPtr;

mlir/lib/Dialect/LLVMIR/Transforms/TypeConsistency.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ static void splitVectorStore(const DataLayout &dataLayout, Location loc,
488488
// Other patterns will turn this into a type-consistent GEP.
489489
auto gepOp = rewriter.create<GEPOp>(
490490
loc, address.getType(), rewriter.getI8Type(), address,
491-
ArrayRef<GEPArg>{storeOffset + index * elementSize});
491+
ArrayRef<GEPArg>{
492+
static_cast<int32_t>(storeOffset + index * elementSize)});
492493

493494
rewriter.create<StoreOp>(loc, extractOp, gepOp);
494495
}
@@ -524,9 +525,9 @@ static void splitIntegerStore(const DataLayout &dataLayout, Location loc,
524525

525526
// We create an `i8` indexed GEP here as that is the easiest (offset is
526527
// already known). Other patterns turn this into a type-consistent GEP.
527-
auto gepOp =
528-
rewriter.create<GEPOp>(loc, address.getType(), rewriter.getI8Type(),
529-
address, ArrayRef<GEPArg>{currentOffset});
528+
auto gepOp = rewriter.create<GEPOp>(
529+
loc, address.getType(), rewriter.getI8Type(), address,
530+
ArrayRef<GEPArg>{static_cast<int32_t>(currentOffset)});
530531
rewriter.create<StoreOp>(loc, valueToStore, gepOp);
531532

532533
// No need to care about padding here since we already checked previously

0 commit comments

Comments
 (0)