[Mlir-commits] [mlir] Fixed Windows build warnings (PR #68978)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Oct 16 03:26:13 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Nikita Kudriavtsev (nikita-kud)
<details>
<summary>Changes</summary>
Fixed a warning encountered during Windows compilation:
- narrowing conversion size_t -> int32_t
- unary minus operator applied to unsigned type, result still unsigned
---
Full diff: https://github.com/llvm/llvm-project/pull/68978.diff
3 Files Affected:
- (modified) llvm/include/llvm/Support/MathExtras.h (+4-1)
- (modified) mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp (+1-1)
- (modified) mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp (+3-2)
``````````diff
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index dc095941fdc8a9f..7278c4eb7695887 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -382,7 +382,10 @@ inline uint64_t alignTo(uint64_t Value, uint64_t Align) {
inline uint64_t alignToPowerOf2(uint64_t Value, uint64_t Align) {
assert(Align != 0 && (Align & (Align - 1)) == 0 &&
"Align must be a power of 2");
- return (Value + Align - 1) & -Align;
+ // Replace unary minus to avoid compilation error on Windows:
+ // "unary minus operator applied to unsigned type, result still unsigned"
+ uint64_t negAlign = (~Align) + 1;
+ return (Value + Align - 1) & negAlign;
}
/// If non-zero \p Skew is specified, the return value will be a minimal integer
diff --git a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
index 96d8fceba706617..d245e3322669667 100644
--- a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
+++ b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
@@ -498,7 +498,7 @@ LogicalResult GPUPrintfOpToVPrintfLowering::matchAndRewrite(
for (auto [index, arg] : llvm::enumerate(args)) {
Value ptr = rewriter.create<LLVM::GEPOp>(
loc, LLVM::LLVMPointerType::get(arg.getType()), tempAlloc,
- ArrayRef<LLVM::GEPArg>{0, index});
+ ArrayRef<LLVM::GEPArg>{0, static_cast<int32_t>(index)});
rewriter.create<LLVM::StoreOp>(loc, arg, ptr);
}
tempAlloc = rewriter.create<LLVM::BitcastOp>(loc, i8Ptr, tempAlloc);
diff --git a/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp b/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
index 097caf23edfa5dd..f39e02a2ac0ad27 100644
--- a/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
+++ b/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
@@ -1036,11 +1036,12 @@ Value ConvertLaunchFuncOpToGpuRuntimeCallPattern::generateParamsArray(
for (const auto &en : llvm::enumerate(arguments)) {
Value fieldPtr = builder.create<LLVM::GEPOp>(
loc, getTypeConverter()->getPointerType(argumentTypes[en.index()]),
- structType, structPtr, ArrayRef<LLVM::GEPArg>{0, en.index()});
+ structType, structPtr,
+ ArrayRef<LLVM::GEPArg>{0, static_cast<int32_t>(en.index())});
builder.create<LLVM::StoreOp>(loc, en.value(), fieldPtr);
auto elementPtr = builder.create<LLVM::GEPOp>(
loc, llvmPointerPointerType, llvmPointerType, arrayPtr,
- ArrayRef<LLVM::GEPArg>{en.index()});
+ ArrayRef<LLVM::GEPArg>{static_cast<int32_t>(en.index())});
if (!getTypeConverter()->useOpaquePointers())
fieldPtr =
builder.create<LLVM::BitcastOp>(loc, llvmPointerType, fieldPtr);
``````````
</details>
https://github.com/llvm/llvm-project/pull/68978
More information about the Mlir-commits
mailing list