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

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 12:57:38 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());
----------------
AtariDreams wrote:

We do not know how it will be interpeted

> 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. #84070

You are correct. Honestly because the tree is working backwards, I do not know how to see how it will be interpreted. 

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


More information about the llvm-commits mailing list