From bb20cf2f1c7ad6ef8a6ab0bc5ca5ea7db4b2282d Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Mon, 22 Feb 2021 18:40:43 +0000 Subject: [PATCH] [KnownBits] Pull out repeated getMinValue() calls from shift analysis. NFCI. --- llvm/lib/Support/KnownBits.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Support/KnownBits.cpp b/llvm/lib/Support/KnownBits.cpp index 6acd841..d7265d0 100644 --- a/llvm/lib/Support/KnownBits.cpp +++ b/llvm/lib/Support/KnownBits.cpp @@ -181,8 +181,9 @@ KnownBits KnownBits::shl(const KnownBits &LHS, const KnownBits &RHS) { unsigned MinTrailingZeros = LHS.countMinTrailingZeros(); // Minimum shift amount low bits are known zero. - if (RHS.getMinValue().ult(BitWidth)) { - MinTrailingZeros += RHS.getMinValue().getZExtValue(); + APInt MinShiftAmount = RHS.getMinValue(); + if (MinShiftAmount.ult(BitWidth)) { + MinTrailingZeros += MinShiftAmount.getZExtValue(); MinTrailingZeros = std::min(MinTrailingZeros, BitWidth); } @@ -208,8 +209,9 @@ KnownBits KnownBits::lshr(const KnownBits &LHS, const KnownBits &RHS) { unsigned MinLeadingZeros = LHS.countMinLeadingZeros(); // Minimum shift amount high bits are known zero. - if (RHS.getMinValue().ult(BitWidth)) { - MinLeadingZeros += RHS.getMinValue().getZExtValue(); + APInt MinShiftAmount = RHS.getMinValue(); + if (MinShiftAmount.ult(BitWidth)) { + MinLeadingZeros += MinShiftAmount.getZExtValue(); MinLeadingZeros = std::min(MinLeadingZeros, BitWidth); } @@ -234,13 +236,14 @@ KnownBits KnownBits::ashr(const KnownBits &LHS, const KnownBits &RHS) { unsigned MinLeadingOnes = LHS.countMinLeadingOnes(); // Minimum shift amount high bits are known sign bits. - if (RHS.getMinValue().ult(BitWidth)) { + APInt MinShiftAmount = RHS.getMinValue(); + if (MinShiftAmount.ult(BitWidth)) { if (MinLeadingZeros) { - MinLeadingZeros += RHS.getMinValue().getZExtValue(); + MinLeadingZeros += MinShiftAmount.getZExtValue(); MinLeadingZeros = std::min(MinLeadingZeros, BitWidth); } if (MinLeadingOnes) { - MinLeadingOnes += RHS.getMinValue().getZExtValue(); + MinLeadingOnes += MinShiftAmount.getZExtValue(); MinLeadingOnes = std::min(MinLeadingOnes, BitWidth); } } -- 2.7.4