[RISCV] Check the sign bits of the input of RISCVISD::ABSW in computeNumSignBitsForTa...
authorCraig Topper <craig.topper@sifive.com>
Wed, 21 Dec 2022 20:50:10 +0000 (12:50 -0800)
committerCraig Topper <craig.topper@sifive.com>
Wed, 21 Dec 2022 20:56:35 +0000 (12:56 -0800)
We created a SIGN_EXTEND_INREG when we created the ABSW so the
input should have 33 sign bits, but check it to be safe.

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

index d34786d..7deccd8 100644 (file)
@@ -10511,6 +10511,14 @@ unsigned RISCVTargetLowering::ComputeNumSignBitsForTargetNode(
         DAG.ComputeNumSignBits(Op.getOperand(4), DemandedElts, Depth + 1);
     return std::min(Tmp, Tmp2);
   }
+  case RISCVISD::ABSW: {
+    // We expand this at isel to negw+max. The result will have 33 sign bits
+    // if the input has at least 33 sign bits.
+    unsigned Tmp =
+        DAG.ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
+    if (Tmp < 33) return 1;
+    return 33;
+  }
   case RISCVISD::SLLW:
   case RISCVISD::SRAW:
   case RISCVISD::SRLW:
@@ -10519,7 +10527,6 @@ unsigned RISCVTargetLowering::ComputeNumSignBitsForTargetNode(
   case RISCVISD::REMUW:
   case RISCVISD::ROLW:
   case RISCVISD::RORW:
-  case RISCVISD::ABSW:
   case RISCVISD::FCVT_W_RV64:
   case RISCVISD::FCVT_WU_RV64:
   case RISCVISD::STRICT_FCVT_W_RV64: