[llvm] [Float2Int] Fix miscompile with floats that can be converted to large values (PR #85996)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 12:45:41 PDT 2024


================
@@ -409,7 +409,8 @@ Value *Float2IntPass::convert(Instruction *I, Type *ToTy) {
     } else if (Instruction *VI = dyn_cast<Instruction>(V)) {
       NewOperands.push_back(convert(VI, ToTy));
     } else if (ConstantFP *CF = dyn_cast<ConstantFP>(V)) {
-      APSInt Val(ToTy->getPrimitiveSizeInBits(), /*isUnsigned=*/false);
+      APSInt Val(ToTy->getPrimitiveSizeInBits(),
+                 !CF->getValueAPF().isNegative());
----------------
topperc wrote:

The parameter to the APSInt constructor should tell how the integer is going to be interpreted by the users. I'm not sure it should be based on the data. We had a bug like this on RISC-V recently. https://github.com/llvm/llvm-project/pull/84070

https://github.com/llvm/llvm-project/pull/85996


More information about the llvm-commits mailing list