From: Craig Topper Date: Thu, 10 Aug 2017 17:48:14 +0000 (+0000) Subject: [InstCombine] Fix a crash in getSelectCondition if we happen to have two inverse... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c2658cfc74924899e8cc186de123110873161daa;p=llvm [InstCombine] Fix a crash in getSelectCondition if we happen to have two inverse vectors of i1 constants. We used to try to truncate the constant vector to vXi1, but if it's already i1 this would fail. Instead we now use IRBuilder::getZExtOrTrunc which should check the type and only create a trunc if needed. I believe this should trigger constant folding in the IRBuilder and ultimately do the same thing just with the additional type check. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310639 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 0aea1edb0d0..bc8b0496ec7 100644 --- a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -1494,8 +1494,9 @@ static Value *getSelectCondition(Value *A, Value *B, // If both operands are constants, see if the constants are inverse bitmasks. Constant *AC, *BC; if (match(A, m_Constant(AC)) && match(B, m_Constant(BC)) && - areInverseVectorBitmasks(AC, BC)) - return ConstantExpr::getTrunc(AC, CmpInst::makeCmpResultType(Ty)); + areInverseVectorBitmasks(AC, BC)) { + return Builder.CreateZExtOrTrunc(AC, CmpInst::makeCmpResultType(Ty)); + } // If both operands are xor'd with constants using the same sexted boolean // operand, see if the constants are inverse bitmasks. diff --git a/test/Transforms/InstCombine/or.ll b/test/Transforms/InstCombine/or.ll index 6ae52d45426..96907cf2bd5 100644 --- a/test/Transforms/InstCombine/or.ll +++ b/test/Transforms/InstCombine/or.ll @@ -828,3 +828,15 @@ define i1 @orn_and_cmp_4(i32 %a, i32 %b, i32 %c) { %or = or i1 %and, %x_inv ret i1 %or } + +; The constant vectors are inverses. Make sure we can turn this into a select without crashing trying to truncate the constant to 16xi1. +define <16 x i1> @test51(<16 x i1> %arg, <16 x i1> %arg1) { +; CHECK-LABEL: @test51( +; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <16 x i1> [[ARG:%.*]], <16 x i1> [[ARG1:%.*]], <16 x i32> +; CHECK-NEXT: ret <16 x i1> [[TMP1]] +; + %tmp = and <16 x i1> %arg, + %tmp2 = and <16 x i1> %arg1, + %tmp3 = or <16 x i1> %tmp, %tmp2 + ret <16 x i1> %tmp3 +}