From: David Majnemer Date: Mon, 27 Oct 2014 05:47:49 +0000 (+0000) Subject: InstCombine: Fix a combine assuming that icmp operands were integers X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=fe58be3733715dd30807e9aaa31500be456ecf53;hp=e250b13ab9728e07308672056905936db53ad855 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 --- diff --git a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp index cbcc85944a7..b41cdc65202 100644 --- a/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -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(Op1)) { // (x ashr x, 31 -> all ones if negative // (x >s -1) ? -1 : 0 -> not (ashr x, 31) -> all ones if positive diff --git a/test/Transforms/InstCombine/cast.ll b/test/Transforms/InstCombine/cast.ll index 7d6a855d58e..578b16d9811 100644 --- a/test/Transforms/InstCombine/cast.ll +++ b/test/Transforms/InstCombine/cast.ll @@ -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]] +}