================
@@ -588,10 +588,17 @@ llvm::Constant *mlir::LLVM::detail::getLLVMConstant(
}
// For integer types, we allow a mismatch in sizes as the index type in
// MLIR might have a different size than the index type in the LLVM module.
- if (auto intAttr = dyn_cast<IntegerAttr>(attr))
- return llvm::ConstantInt::get(
- llvmType,
- intAttr.getValue().sextOrTrunc(llvmType->getIntegerBitWidth()));
+ if (auto intAttr = dyn_cast<IntegerAttr>(attr)) {
+ // If the attribute is an unsigned integer or a 1-bit integer, zero-extend
+ // the value to the bit width of the LLVM type. Otherwise, sign-extend.
+ auto intTy = mlir::dyn_cast<IntegerType>(intAttr.getType());
+ APInt value;
+ if (intTy && (intTy.isUnsigned() || intTy.getWidth() == 1))
----------------
andykaylor wrote:
I wasn't entirely sure what the condition should be here. Sign-extending a
signless value feels a bit arbitrary, but I think that's the behavior that's
expected for index types, so I guess it makes sense for signless integers also.
My motivation in making this change is that in global initializers `true` was
being translated to `i8 -1` whereas in local initializers it was `i8 1`.
https://github.com/llvm/llvm-project/pull/169751
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits