https://github.com/andykaylor created 
https://github.com/llvm/llvm-project/pull/69797

None

>From 856a471b40f19f5fcf6aab7591009555b6a3841f Mon Sep 17 00:00:00 2001
From: Andy Kaylor <andrew.kay...@intel.com>
Date: Fri, 20 Oct 2023 12:33:51 -0700
Subject: [PATCH 1/2] Update SimplifyIndVar.cpp

In SimplifyIndvar::replaceFloatIVWithIntegerIV() the return value of 
getFPMantissaWidth() was being cast as an unsigned integer and then compared 
with the number of bits needed to represent an integer that was cast to and 
from a floating-point type. This is a problem because getFPMantissaWidth() 
returns -1 if the type does not have a stable mantissa.

Currently the only type that returns -1 is ppc_fp128, so you'd need a pretty 
big induction variable to cause a problem. However, this problem will be more 
likely to be exposed when we implement support for decimal floating-point types.

Strictly speaking, what we want to know here is the size of the biggest integer 
that can be represented exactly. We could get that information even with an 
unstable mantissa width, but getFPMantissaWidth() won't do it.
---
 llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp 
b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index 1caf708bcc35254..45cbdd235898b28 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -664,7 +664,7 @@ bool 
SimplifyIndvar::replaceFloatIVWithIntegerIV(Instruction *UseInst) {
     MaskBits = SE->getSignedRange(IV).getMinSignedBits();
   else
     MaskBits = SE->getUnsignedRange(IV).getActiveBits();
-  unsigned DestNumSigBits = UseInst->getType()->getFPMantissaWidth();
+  int DestNumSigBits = UseInst->getType()->getFPMantissaWidth();
   if (MaskBits <= DestNumSigBits) {
     for (User *U : UseInst->users()) {
       // Match for fptosi/fptoui of sitofp and with same type.

>From 2524d41a34ccaa3932e5b4ab2876ea02744f6304 Mon Sep 17 00:00:00 2001
From: Andy Kaylor <andrew.kay...@intel.com>
Date: Fri, 20 Oct 2023 16:40:26 -0700
Subject: [PATCH 2/2] Fix build warning

This fixes a build warning caused by mixed signed/unsigned compare
---
 llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp 
b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index 45cbdd235898b28..a23ac41acaa58aa 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -659,11 +659,11 @@ bool 
SimplifyIndvar::replaceFloatIVWithIntegerIV(Instruction *UseInst) {
   Instruction *IVOperand = cast<Instruction>(UseInst->getOperand(0));
   // Get the symbolic expression for this instruction.
   const SCEV *IV = SE->getSCEV(IVOperand);
-  unsigned MaskBits;
+  int MaskBits;
   if (UseInst->getOpcode() == CastInst::SIToFP)
-    MaskBits = SE->getSignedRange(IV).getMinSignedBits();
+    MaskBits = (int)SE->getSignedRange(IV).getMinSignedBits();
   else
-    MaskBits = SE->getUnsignedRange(IV).getActiveBits();
+    MaskBits = (int)SE->getUnsignedRange(IV).getActiveBits();
   int DestNumSigBits = UseInst->getType()->getFPMantissaWidth();
   if (MaskBits <= DestNumSigBits) {
     for (User *U : UseInst->users()) {

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to