diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -664,8 +664,7 @@ C1Log = C1->logBase2(); IsEqualZero = IC->getPredicate() == ICmpInst::ICMP_EQ; } else { - // We also need to recognize (icmp slt (trunc (X)), 0) and - // (icmp sgt (trunc (X)), -1). + // We also need to recognize (icmp slt X, 0) and (icmp sgt X, -1). if (IC->getPredicate() == ICmpInst::ICMP_SGT && match(CmpRHS, m_AllOnes())) IsEqualZero = true; if (IC->getPredicate() == ICmpInst::ICMP_SLT && match(CmpRHS, m_Zero())) @@ -673,9 +672,6 @@ else return nullptr; - if (!match(CmpLHS, m_OneUse(m_Trunc(m_Value(V))))) - return nullptr; - C1Log = CmpLHS->getType()->getScalarSizeInBits() - 1; NeedAnd = true; } diff --git a/llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll b/llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll --- a/llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll +++ b/llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll @@ -760,9 +760,9 @@ define i8 @test70(i8 %x, i8 %y) { ; CHECK-LABEL: @test70( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0 -; CHECK-NEXT: [[OR:%.*]] = or i8 [[Y:%.*]], 2 -; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i8 [[OR]], i8 [[Y]] +; CHECK-NEXT: [[TMP1:%.*]] = lshr i8 [[X:%.*]], 6 +; CHECK-NEXT: [[TMP2:%.*]] = and i8 [[TMP1]], 2 +; CHECK-NEXT: [[SELECT:%.*]] = or i8 [[TMP2]], [[Y:%.*]] ; CHECK-NEXT: ret i8 [[SELECT]] ; %cmp = icmp slt i8 %x, 0