llvm.org GIT mirror llvm / 70eff63
Revert the part of r107257 which introduced new logic for using nsw and nuw flags from IR Instructions. On further consideration, this isn't valid. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107298 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 9 years ago
2 changed file(s) with 15 addition(s) and 85 deletion(s). Raw diff Collapse all Expand all
27592759 return getUnknown(PN);
27602760 }
27612761
2762 /// UseFlag - When creating an operator with operands L and R based on an
2763 /// LLVM IR instruction in basic block BB where the instruction has
2764 /// nsw, nuw, or inbounds, test whether the corresponding flag can be
2765 /// set for the resulting SCEV.
2766 static bool
2767 UseFlag(bool Flag, const SCEV *L, const SCEV *R, const Value *Inst) {
2768 // If the flag is not set, don't use it. This is included here to reduce
2769 // clutter in the callers.
2770 if (!Flag)
2771 return false;
2772
2773 // Determine the block which contains the instruction with the flag.
2774 const Instruction *I = dyn_cast(Inst);
2775 if (!I)
2776 return false;
2777 const BasicBlock *BB = I->getParent();
2778
2779 // Handle an easy case: test if exactly one of the operands is an addrec
2780 // and that the instruction is trivially control-equivalent to the addrec's
2781 // loop's header.
2782 if (const SCEVAddRecExpr *AR = dyn_cast(L)) {
2783 if (!isa(R) &&
2784 AR->getLoop()->getHeader() == BB)
2785 return true;
2786 } else if (const SCEVAddRecExpr *AR = dyn_cast(R)) {
2787 if (AR->getLoop()->getHeader() == BB)
2788 return true;
2789 }
2790
2791 return false;
2792 }
2793
27942762 /// createNodeForGEP - Expand GEP instructions into add and multiply
27952763 /// operations. This allows them to be analyzed by regular SCEV code.
27962764 ///
27992767 // Don't blindly transfer the inbounds flag from the GEP instruction to the
28002768 // Add expression, because the Instruction may be guarded by control flow
28012769 // and the no-overflow bits may not be valid for the expression in any
2802 // context. However, in the special case where the GEP is in the loop header,
2803 // we know it's trivially control-equivalent to any addrecs for that loop.
2804 bool InBounds = GEP->isInBounds();
2770 // context.
28052771
28062772 const Type *IntPtrTy = getEffectiveSCEVType(GEP->getType());
28072773 Value *Base = GEP->getOperand(0);
28202786 unsigned FieldNo = cast(Index)->getZExtValue();
28212787 const SCEV *FieldOffset = getOffsetOfExpr(STy, FieldNo);
28222788
2823 // Test if the GEP has the inbounds keyword and is control-equivalent
2824 // to the addrec.
2825 bool HasNUW = UseFlag(InBounds, TotalOffset, FieldOffset, GEP);
2826
28272789 // Add the field offset to the running total offset.
2828 TotalOffset = getAddExpr(TotalOffset, FieldOffset,
2829 HasNUW, /*HasNSW=*/false);
2790 TotalOffset = getAddExpr(TotalOffset, FieldOffset);
28302791 } else {
28312792 // For an array, add the element offset, explicitly scaled.
28322793 const SCEV *ElementSize = getSizeOfExpr(*GTI);
28342795 // Getelementptr indices are signed.
28352796 IndexS = getTruncateOrSignExtend(IndexS, IntPtrTy);
28362797
2837 // Test if the GEP has the inbounds keyword and is control-equivalent
2838 // to the addrec.
2839 bool HasNUW = UseFlag(InBounds, IndexS, ElementSize, GEP);
2840
28412798 // Multiply the index by the element size to compute the element offset.
2842 const SCEV *LocalOffset = getMulExpr(IndexS, ElementSize,
2843 HasNUW, /*HasNSW=*/false);
2844
2845 // Test if the GEP has the inbounds keyword and is control-equivalent
2846 // to the addrec.
2847 HasNUW = UseFlag(InBounds, TotalOffset, LocalOffset, GEP);
2799 const SCEV *LocalOffset = getMulExpr(IndexS, ElementSize);
28482800
28492801 // Add the element offset to the running total offset.
2850 TotalOffset = getAddExpr(TotalOffset, LocalOffset,
2851 HasNUW, /*HasNSW=*/false);
2802 TotalOffset = getAddExpr(TotalOffset, LocalOffset);
28522803 }
28532804 }
28542805
28552806 // Get the SCEV for the GEP base.
28562807 const SCEV *BaseS = getSCEV(Base);
28572808
2858 // Test if the GEP has the inbounds keyword and is control-equivalent
2859 // to the addrec.
2860 bool HasNUW = UseFlag(InBounds, BaseS, TotalOffset, GEP);
2861
28622809 // Add the total offset from all the GEP indices to the base.
2863 return getAddExpr(BaseS, TotalOffset, HasNUW, /*HasNSW=*/false);
2810 return getAddExpr(BaseS, TotalOffset);
28642811 }
28652812
28662813 /// GetMinTrailingZeros - Determine the minimum number of zero bits that S is
32523199
32533200 Operator *U = cast(V);
32543201 switch (Opcode) {
3255 case Instruction::Add: {
3256 const SCEV *LHS = getSCEV(U->getOperand(0));
3257 const SCEV *RHS = getSCEV(U->getOperand(1));
3258
3259 // Don't transfer the NSW and NUW bits from the Add instruction to the
3260 // Add expression unless we can prove that it's safe.
3261 AddOperator *Add = cast(U);
3262 bool HasNUW = UseFlag(Add->hasNoUnsignedWrap(), LHS, RHS, Add);
3263 bool HasNSW = UseFlag(Add->hasNoSignedWrap(), LHS, RHS, Add);
3264
3265 return getAddExpr(LHS, RHS, HasNUW, HasNSW);
3266 }
3267 case Instruction::Mul: {
3268 const SCEV *LHS = getSCEV(U->getOperand(0));
3269 const SCEV *RHS = getSCEV(U->getOperand(1));
3270
3271 // Don't transfer the NSW and NUW bits from the Mul instruction to the
3272 // Mul expression unless we can prove that it's safe.
3273 MulOperator *Mul = cast(U);
3274 bool HasNUW = UseFlag(Mul->hasNoUnsignedWrap(), LHS, RHS, Mul);
3275 bool HasNSW = UseFlag(Mul->hasNoSignedWrap(), LHS, RHS, Mul);
3276
3277 return getMulExpr(LHS, RHS, HasNUW, HasNSW);
3278 }
3202 case Instruction::Add:
3203 return getAddExpr(getSCEV(U->getOperand(0)),
3204 getSCEV(U->getOperand(1)));
3205 case Instruction::Mul:
3206 return getMulExpr(getSCEV(U->getOperand(0)),
3207 getSCEV(U->getOperand(1)));
32793208 case Instruction::UDiv:
32803209 return getUDivExpr(getSCEV(U->getOperand(0)),
32813210 getSCEV(U->getOperand(1)));
189189 ret void
190190 }
191191
192 ; TODO: This is theoretically provable to be NoAlias.
192193 ; CHECK: Function: nonnegative: 2 pointers, 0 call sites
193 ; CHECK: NoAlias: i64* %arrayidx, i64* %p
194 ; CHECK: MayAlias: i64* %arrayidx, i64* %p
194195
195196 define void @nonnegative(i64* %p) nounwind {
196197 entry:
209210 ret void
210211 }
211212
212 ; CHECK: 14 no alias responses
213 ; CHECK: 26 may alias responses
213 ; CHECK: 13 no alias responses
214 ; CHECK: 27 may alias responses
214215 ; CHECK: 18 must alias responses