diff options
author | Chris Lattner <sabre@nondot.org> | 2010-01-10 02:22:12 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-01-10 02:22:12 +0000 |
commit | d26c9e183e56d09f48d7074be4cacce099338316 (patch) | |
tree | b46bcf64ab43a254e8a455e9c8b09eb570cf5951 /lib/Transforms | |
parent | 3f7dc880c4b558655cb8868ce29e1d2b27e2ea51 (diff) | |
download | external_llvm-d26c9e183e56d09f48d7074be4cacce099338316.zip external_llvm-d26c9e183e56d09f48d7074be4cacce099338316.tar.gz external_llvm-d26c9e183e56d09f48d7074be4cacce099338316.tar.bz2 |
enhance CanEvaluateZExtd to handle shift left and sext, allowing
more expressions to be promoted and casts eliminated.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93096 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCasts.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp index a6833b8..3ad786b 100644 --- a/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -643,17 +643,31 @@ static int CanEvaluateZExtd(Value *V, const Type *Ty,unsigned &NumCastsRemoved, if (Tmp1 == -1) return -1; Tmp2 = CanEvaluateZExtd(I->getOperand(1), Ty, NumCastsRemoved, TD); if (Tmp2 == -1) return -1; + return 0; // TODO: Could be improved. + + case Instruction::Shl: + Tmp1 = CanEvaluateZExtd(I->getOperand(0), Ty, NumCastsRemoved, TD); + if (Tmp1 == -1) return -1; + + if (ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1))) + return Tmp1 - CI->getZExtValue(); + + // Variable shift, no known zext bits. + Tmp2 = CanEvaluateZExtd(I->getOperand(1), Ty, NumCastsRemoved, TD); + if (Tmp2 == -1) return -1; return 0; - //case Instruction::Shl: //case Instruction::LShr: case Instruction::ZExt: // zext(zext(x)) -> zext(x). Since we're replacing it, it isn't eliminated. Tmp1 = Ty->getScalarSizeInBits()-OrigTy->getScalarSizeInBits(); return GetLeadingZeros(I, TD)+Tmp1; - //case Instruction::SExt: zext(sext(x)) -> sext(x) with no upper bits known. - //case Instruction::Trunc: + case Instruction::SExt: + // zext(sext(x)) -> sext(x) with no upper bits known. + return 0; + //case Instruction::Trunc: -> Could turn into AND. + case Instruction::Select: Tmp1 = CanEvaluateZExtd(I->getOperand(1), Ty, NumCastsRemoved, TD); if (Tmp1 == -1) return -1; |