InstCombine: Fix a combine assuming that icmp operands were integers

An icmp may have pointer arguments, it isn't limited to integers or
vectors of integers.

This fixes PR21388.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220664 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer 2014-10-27 05:47:49 +00:00
parent e250b13ab9
commit fe58be3733
2 changed files with 13 additions and 0 deletions

View File

@ -900,6 +900,10 @@ Instruction *InstCombiner::transformSExtICmp(ICmpInst *ICI, Instruction &CI) {
Value *Op0 = ICI->getOperand(0), *Op1 = ICI->getOperand(1);
ICmpInst::Predicate Pred = ICI->getPredicate();
// Don't bother if Op1 isn't of vector or integer type.
if (!Op1->getType()->isIntOrIntVectorTy())
return nullptr;
if (Constant *Op1C = dyn_cast<Constant>(Op1)) {
// (x <s 0) ? -1 : 0 -> ashr x, 31 -> all ones if negative
// (x >s -1) ? -1 : 0 -> not (ashr x, 31) -> all ones if positive

View File

@ -1084,3 +1084,12 @@ define float @overflow_sitofp() {
; CHECK-NEXT: ret float undef
}
define i32 @PR21388(i32* %v) {
%icmp = icmp slt i32* %v, null
%sext = sext i1 %icmp to i32
ret i32 %sext
; CHECK-LABEL: @PR21388(
; CHECK-NEXT: %[[icmp:.*]] = icmp slt i32* %v, null
; CHECK-NEXT: %[[sext:.*]] = sext i1 %[[icmp]] to i32
; CHECK-NEXT: ret i32 %[[sext]]
}