A->getType()->isIntOrIntVectorTy(1))
return SelectInst::Create(A, Op0, Constant::getNullValue(Ty));
- // and(ashr(subNSW(Y, X), ScalarSizeInBits(Y)-1), X) --> X s> Y ? X : 0.
- // TODO: This is a specific case of the more general pattern below, so it
- // should be removed.
+ // (iN X s>> (N-1)) & Y --> (X s< 0) ? Y : 0
unsigned FullShift = Ty->getScalarSizeInBits() - 1;
- if (match(&I, m_c_And(m_OneUse(m_AShr(m_NSWSub(m_Value(Y), m_Value(X)),
- m_SpecificInt(FullShift))),
- m_Deferred(X)))) {
- Value *NewICmpInst = Builder.CreateICmpSGT(X, Y);
- return SelectInst::Create(NewICmpInst, X, ConstantInt::getNullValue(Ty));
- }
-
- // (iN X s>> (N-1)) & Y --> (X < 0) ? Y : 0
if (match(&I, m_c_And(m_OneUse(m_AShr(m_Value(X), m_SpecificInt(FullShift))),
m_Value(Y)))) {
Constant *Zero = ConstantInt::getNullValue(Ty);
; CHECK-LABEL: @sub_ashr_and_i32_extra_use_sub(
; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: store i32 [[SUB]], i32* [[P:%.*]], align 4
-; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[Y]], [[X]]
-; CHECK-NEXT: [[AND:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 0
+; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt i32 [[SUB]], 0
+; CHECK-NEXT: [[AND:%.*]] = select i1 [[ISNEG]], i32 [[X]], i32 0
; CHECK-NEXT: ret i32 [[AND]]
;
%sub = sub nsw i32 %y, %x