Author: hans Date: Thu Jul 28 10:25:03 2016 New Revision: 276986 URL: http://llvm.org/viewvc/llvm-project?rev=276986&view=rev Log: Back-port r276209: ------------------------------------------------------------------------ r276209 | spatel | 2016-07-20 16:40:01 -0700 (Wed, 20 Jul 2016) | 4 lines
[InstSimplify][InstCombine] don't crash when folding vector selects of icmp Differential Revision: https://reviews.llvm.org/D22602 ------------------------------------------------------------------------ Modified: llvm/branches/release_39/ (props changed) llvm/branches/release_39/lib/Analysis/InstructionSimplify.cpp llvm/branches/release_39/lib/Transforms/InstCombine/InstCombineSelect.cpp llvm/branches/release_39/test/Transforms/InstCombine/select.ll Propchange: llvm/branches/release_39/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Jul 28 10:25:03 2016 @@ -1,3 +1,3 @@ /llvm/branches/Apple/Pertwee:110850,110961 /llvm/branches/type-system-rewrite:133420-134817 -/llvm/trunk:155241,275870,275879,275898,275928,275935,275946,275978,276015,276077,276109,276181,276236-276237,276358,276364,276368,276389,276438,276479,276510 +/llvm/trunk:155241,275870,275879,275898,275928,275935,275946,275978,276015,276077,276109,276181,276209,276236-276237,276358,276364,276368,276389,276438,276479,276510 Modified: llvm/branches/release_39/lib/Analysis/InstructionSimplify.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/lib/Analysis/InstructionSimplify.cpp?rev=276986&r1=276985&r2=276986&view=diff ============================================================================== --- llvm/branches/release_39/lib/Analysis/InstructionSimplify.cpp (original) +++ llvm/branches/release_39/lib/Analysis/InstructionSimplify.cpp Thu Jul 28 10:25:03 2016 @@ -3400,7 +3400,10 @@ static Value *SimplifySelectInst(Value * return TrueVal; if (const auto *ICI = dyn_cast<ICmpInst>(CondVal)) { - unsigned BitWidth = Q.DL.getTypeSizeInBits(TrueVal->getType()); + // FIXME: This code is nearly duplicated in InstCombine. Using/refactoring + // decomposeBitTestICmp() might help. + unsigned BitWidth = + Q.DL.getTypeSizeInBits(TrueVal->getType()->getScalarType()); ICmpInst::Predicate Pred = ICI->getPredicate(); Value *CmpLHS = ICI->getOperand(0); Value *CmpRHS = ICI->getOperand(1); Modified: llvm/branches/release_39/lib/Transforms/InstCombine/InstCombineSelect.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/lib/Transforms/InstCombine/InstCombineSelect.cpp?rev=276986&r1=276985&r2=276986&view=diff ============================================================================== --- llvm/branches/release_39/lib/Transforms/InstCombine/InstCombineSelect.cpp (original) +++ llvm/branches/release_39/lib/Transforms/InstCombine/InstCombineSelect.cpp Thu Jul 28 10:25:03 2016 @@ -553,8 +553,11 @@ Instruction *InstCombiner::visitSelectIn } } + // FIXME: This code is nearly duplicated in InstSimplify. Using/refactoring + // decomposeBitTestICmp() might help. { - unsigned BitWidth = DL.getTypeSizeInBits(TrueVal->getType()); + unsigned BitWidth = + DL.getTypeSizeInBits(TrueVal->getType()->getScalarType()); APInt MinSignedValue = APInt::getSignBit(BitWidth); Value *X; const APInt *Y, *C; Modified: llvm/branches/release_39/test/Transforms/InstCombine/select.ll URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/test/Transforms/InstCombine/select.ll?rev=276986&r1=276985&r2=276986&view=diff ============================================================================== --- llvm/branches/release_39/test/Transforms/InstCombine/select.ll (original) +++ llvm/branches/release_39/test/Transforms/InstCombine/select.ll Thu Jul 28 10:25:03 2016 @@ -1737,3 +1737,26 @@ define i32 @PR27137(i32 %a) { %s1 = select i1 %c1, i32 %s0, i32 -1 ret i32 %s1 } + +define i32 @select_icmp_slt0_xor(i32 %x) { +; CHECK-LABEL: @select_icmp_slt0_xor( +; CHECK-NEXT: [[TMP1:%.*]] = or i32 %x, -2147483648 +; CHECK-NEXT: ret i32 [[TMP1]] +; + %cmp = icmp slt i32 %x, zeroinitializer + %xor = xor i32 %x, 2147483648 + %x.xor = select i1 %cmp, i32 %x, i32 %xor + ret i32 %x.xor +} + +define <2 x i32> @select_icmp_slt0_xor_vec(<2 x i32> %x) { +; CHECK-LABEL: @select_icmp_slt0_xor_vec( +; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> %x, <i32 -2147483648, i32 -2147483648> +; CHECK-NEXT: ret <2 x i32> [[TMP1]] +; + %cmp = icmp slt <2 x i32> %x, zeroinitializer + %xor = xor <2 x i32> %x, <i32 2147483648, i32 2147483648> + %x.xor = select <2 x i1> %cmp, <2 x i32> %x, <2 x i32> %xor + ret <2 x i32> %x.xor +} + _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits