ConstantFold: Check that truncating the other side is safe under a sext when trying to remove a sext from a compare.

Fixes PR16462.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185284 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer
2013-06-30 13:47:43 +00:00
parent 58b6dc032a
commit 80c070493d
2 changed files with 19 additions and 5 deletions

View File

@@ -1857,9 +1857,9 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
if (CE1Inverse == CE1Op0) {
// Check whether we can safely truncate the right hand side.
Constant *C2Inverse = ConstantExpr::getTrunc(C2, CE1Op0->getType());
if (ConstantExpr::getZExt(C2Inverse, C2->getType()) == C2) {
if (ConstantExpr::getCast(CE1->getOpcode(), C2Inverse,
C2->getType()) == C2)
return ConstantExpr::getICmp(pred, CE1Inverse, C2Inverse);
}
}
}
}