diff options
| author | Roman Lebedev <lebedev.ri@gmail.com> | 2019-09-11 15:32:46 +0000 | 
|---|---|---|
| committer | Roman Lebedev <lebedev.ri@gmail.com> | 2019-09-11 15:32:46 +0000 | 
| commit | 00c1ee48e4cf2a6ce67dc96342b1b07625d0a7b4 (patch) | |
| tree | 9e71cb23f1e3d3f5fd7ff2c69bdd4ffc6e2f308e | |
| parent | 8aeb7bb013affb691cc417fcb50049bffcc158eb (diff) | |
| download | bcm5719-llvm-00c1ee48e4cf2a6ce67dc96342b1b07625d0a7b4.tar.gz bcm5719-llvm-00c1ee48e4cf2a6ce67dc96342b1b07625d0a7b4.zip  | |
[InstSimplify] Pass SimplifyQuery into simplifyUnsignedRangeCheck() and use it for isKnownNonZero()
This was actually the original intention in D67332,
but i messed up and forgot about it.
This patch was originally part of D67411, but precommitting this.
llvm-svn: 371630
| -rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 32 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstSimplify/redundant-null-check-in-uadd_with_overflow-of-nonnull-ptr.ll | 4 | 
2 files changed, 16 insertions, 20 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 7960635d009..5e3a22aba96 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1372,7 +1372,7 @@ Value *llvm::SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact,  /// with the parameters swapped.  static Value *simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp,                                           ICmpInst *UnsignedICmp, bool IsAnd, -                                         const DataLayout &DL) { +                                         const SimplifyQuery &Q) {    Value *X, *Y;    ICmpInst::Predicate EqPred; @@ -1399,13 +1399,13 @@ static Value *simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp,    // X <= Y && Y != 0  -->  X <= Y  iff X != 0    // X <= Y || Y != 0  -->  Y != 0  iff X != 0    if (UnsignedPred == ICmpInst::ICMP_ULE && EqPred == ICmpInst::ICMP_NE && -      isKnownNonZero(X, DL)) +      isKnownNonZero(X, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))      return IsAnd ? UnsignedICmp : ZeroICmp;    // X > Y && Y == 0  -->  Y == 0  iff X != 0    // X > Y || Y == 0  -->  X > Y   iff X != 0    if (UnsignedPred == ICmpInst::ICMP_UGT && EqPred == ICmpInst::ICMP_EQ && -      isKnownNonZero(X, DL)) +      isKnownNonZero(X, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))      return IsAnd ? ZeroICmp : UnsignedICmp;    // X >= Y || Y != 0  -->  true @@ -1600,11 +1600,10 @@ static Value *simplifyAndOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1,  }  static Value *simplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1, -                                 const InstrInfoQuery &IIQ, -                                 const DataLayout &DL) { -  if (Value *X = simplifyUnsignedRangeCheck(Op0, Op1, /*IsAnd=*/true, DL)) +                                 const SimplifyQuery &Q) { +  if (Value *X = simplifyUnsignedRangeCheck(Op0, Op1, /*IsAnd=*/true, Q))      return X; -  if (Value *X = simplifyUnsignedRangeCheck(Op1, Op0, /*IsAnd=*/true, DL)) +  if (Value *X = simplifyUnsignedRangeCheck(Op1, Op0, /*IsAnd=*/true, Q))      return X;    if (Value *X = simplifyAndOfICmpsWithSameOperands(Op0, Op1)) @@ -1618,9 +1617,9 @@ static Value *simplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1,    if (Value *X = simplifyAndOrOfICmpsWithZero(Op0, Op1, true))      return X; -  if (Value *X = simplifyAndOfICmpsWithAdd(Op0, Op1, IIQ)) +  if (Value *X = simplifyAndOfICmpsWithAdd(Op0, Op1, Q.IIQ))      return X; -  if (Value *X = simplifyAndOfICmpsWithAdd(Op1, Op0, IIQ)) +  if (Value *X = simplifyAndOfICmpsWithAdd(Op1, Op0, Q.IIQ))      return X;    return nullptr; @@ -1674,11 +1673,10 @@ static Value *simplifyOrOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1,  }  static Value *simplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1, -                                const InstrInfoQuery &IIQ, -                                const DataLayout &DL) { -  if (Value *X = simplifyUnsignedRangeCheck(Op0, Op1, /*IsAnd=*/false, DL)) +                                const SimplifyQuery &Q) { +  if (Value *X = simplifyUnsignedRangeCheck(Op0, Op1, /*IsAnd=*/false, Q))      return X; -  if (Value *X = simplifyUnsignedRangeCheck(Op1, Op0, /*IsAnd=*/false, DL)) +  if (Value *X = simplifyUnsignedRangeCheck(Op1, Op0, /*IsAnd=*/false, Q))      return X;    if (Value *X = simplifyOrOfICmpsWithSameOperands(Op0, Op1)) @@ -1692,9 +1690,9 @@ static Value *simplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1,    if (Value *X = simplifyAndOrOfICmpsWithZero(Op0, Op1, false))      return X; -  if (Value *X = simplifyOrOfICmpsWithAdd(Op0, Op1, IIQ)) +  if (Value *X = simplifyOrOfICmpsWithAdd(Op0, Op1, Q.IIQ))      return X; -  if (Value *X = simplifyOrOfICmpsWithAdd(Op1, Op0, IIQ)) +  if (Value *X = simplifyOrOfICmpsWithAdd(Op1, Op0, Q.IIQ))      return X;    return nullptr; @@ -1753,8 +1751,8 @@ static Value *simplifyAndOrOfCmps(const SimplifyQuery &Q,    auto *ICmp0 = dyn_cast<ICmpInst>(Op0);    auto *ICmp1 = dyn_cast<ICmpInst>(Op1);    if (ICmp0 && ICmp1) -    V = IsAnd ? simplifyAndOfICmps(ICmp0, ICmp1, Q.IIQ, Q.DL) -              : simplifyOrOfICmps(ICmp0, ICmp1, Q.IIQ, Q.DL); +    V = IsAnd ? simplifyAndOfICmps(ICmp0, ICmp1, Q) +              : simplifyOrOfICmps(ICmp0, ICmp1, Q);    auto *FCmp0 = dyn_cast<FCmpInst>(Op0);    auto *FCmp1 = dyn_cast<FCmpInst>(Op1); diff --git a/llvm/test/Transforms/InstSimplify/redundant-null-check-in-uadd_with_overflow-of-nonnull-ptr.ll b/llvm/test/Transforms/InstSimplify/redundant-null-check-in-uadd_with_overflow-of-nonnull-ptr.ll index 8fb32e11513..d409aecf52e 100644 --- a/llvm/test/Transforms/InstSimplify/redundant-null-check-in-uadd_with_overflow-of-nonnull-ptr.ll +++ b/llvm/test/Transforms/InstSimplify/redundant-null-check-in-uadd_with_overflow-of-nonnull-ptr.ll @@ -251,10 +251,8 @@ define i1 @t16(i64 %base, i64 %offset) {  ; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i64 [[BASE:%.*]], 0  ; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])  ; CHECK-NEXT:    [[ADJUSTED:%.*]] = add i64 [[BASE]], [[OFFSET:%.*]] -; CHECK-NEXT:    [[NON_NULL_AFTER_ADJUSTMENT:%.*]] = icmp ne i64 [[ADJUSTED]], 0  ; CHECK-NEXT:    [[NO_OVERFLOW_DURING_ADJUSTMENT:%.*]] = icmp uge i64 [[ADJUSTED]], [[BASE]] -; CHECK-NEXT:    [[RES:%.*]] = and i1 [[NON_NULL_AFTER_ADJUSTMENT]], [[NO_OVERFLOW_DURING_ADJUSTMENT]] -; CHECK-NEXT:    ret i1 [[RES]] +; CHECK-NEXT:    ret i1 [[NO_OVERFLOW_DURING_ADJUSTMENT]]  ;    %cmp = icmp slt i64 %base, 0    call void @llvm.assume(i1 %cmp)  | 

