From 1c61accbde8b6b2d18d023955dea93b2e27cfb0b Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Tue, 2 May 2023 12:56:37 -0700 Subject: [PATCH] [CodeGen] Fix signed int overflow Exposed by the test from 8f966cedea594d9a91e585e88a80a42c04049e6c. --- llvm/include/llvm/CodeGen/TargetLowering.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h index 7ea7980..56a067a 100644 --- a/llvm/include/llvm/CodeGen/TargetLowering.h +++ b/llvm/include/llvm/CodeGen/TargetLowering.h @@ -2298,11 +2298,11 @@ public: /// considered beneficial. /// If optimizing for size, expansion is only considered beneficial for upto /// 5 multiplies and a divide (if the exponent is negative). - bool isBeneficialToExpandPowI(int Exponent, bool OptForSize) const { + bool isBeneficialToExpandPowI(int64_t Exponent, bool OptForSize) const { if (Exponent < 0) Exponent = -Exponent; - return !OptForSize || - (llvm::popcount((unsigned int)Exponent) + Log2_32(Exponent) < 7); + uint64_t E = static_cast(Exponent); + return !OptForSize || (llvm::popcount(E) + Log2_64(E) < 7); } //===--------------------------------------------------------------------===// -- 2.7.4