[llvm] r265954 - [InstCombine] rename variables in shifted-shift helper function (NFCI)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 11 09:11:08 PDT 2016
Author: spatel
Date: Mon Apr 11 11:11:07 2016
New Revision: 265954
URL: http://llvm.org/viewvc/llvm-project?rev=265954&view=rev
Log:
[InstCombine] rename variables in shifted-shift helper function (NFCI)
This is step 3 of refactoring to solve PR26760:
https://llvm.org/bugs/show_bug.cgi?id=26760
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp?rev=265954&r1=265953&r2=265954&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp Mon Apr 11 11:11:07 2016
@@ -59,31 +59,34 @@ Instruction *InstCombiner::commonShiftTr
/// that have constant shift amounts.
/// FIXME: This can be extended to handle either a shl or lshr instruction, but
/// it is currently only valid for a shl.
-static bool canEvaluateShiftedShift(unsigned NumBits, bool IsLeftShift,
- Instruction *I, InstCombiner &IC,
+static bool canEvaluateShiftedShift(unsigned FirstShiftAmt,
+ bool IsFirstShiftLeft,
+ Instruction *SecondShift, InstCombiner &IC,
Instruction *CxtI) {
- // We can often fold the shift into shifts-by-a-constant.
- ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1));
- if (!CI)
+ // We need constant shifts.
+ auto *SecondShiftConst = dyn_cast<ConstantInt>(SecondShift->getOperand(1));
+ if (!SecondShiftConst)
return false;
- // We can always fold shl(c1)+shl(c2) -> shl(c1+c2).
- if (IsLeftShift)
+ unsigned SecondShiftAmt = SecondShiftConst->getZExtValue();
+
+ // We can always fold shl(c1) + shl(c2) -> shl(c1+c2).
+ if (IsFirstShiftLeft)
return true;
- // We can always turn shl(c)+shr(c) -> and(c2).
- if (CI->getValue() == NumBits)
+ // We can always fold shr(c) + shl(c) -> and(c2).
+ if (SecondShiftAmt == FirstShiftAmt)
return true;
- unsigned TypeWidth = I->getType()->getScalarSizeInBits();
+ unsigned TypeWidth = SecondShift->getType()->getScalarSizeInBits();
- // We can turn shl(c1)+shr(c2) -> shl(c3)+and(c4), but it isn't
- // profitable unless we know the and'd out bits are already zero.
- if (CI->getZExtValue() > NumBits) {
- unsigned LowBits = TypeWidth - CI->getZExtValue();
- if (IC.MaskedValueIsZero(
- I->getOperand(0),
- APInt::getLowBitsSet(TypeWidth, NumBits) << LowBits, 0, CxtI))
+ // If the 2nd shift is bigger than the 1st, we can fold:
+ // shr(c1) + shl(c2) -> shl(c3) + and(c4)
+ // but it isn't profitable unless we know the and'd out bits are already zero.
+ if (SecondShiftAmt > FirstShiftAmt) {
+ unsigned MaskShift = TypeWidth - SecondShiftAmt;
+ APInt Mask = APInt::getLowBitsSet(TypeWidth, FirstShiftAmt) << MaskShift;
+ if (IC.MaskedValueIsZero(SecondShift->getOperand(0), Mask, 0, CxtI))
return true;
}
More information about the llvm-commits
mailing list