llvm.org GIT mirror llvm / 040b064
Merging r296992: ------------------------------------------------------------------------ r296992 | sanjoy | 2017-03-05 15:49:17 -0800 (Sun, 05 Mar 2017) | 7 lines [SCEV] Decrease the recursion threshold for CompareValueComplexity Fixes PR32142. r287232 accidentally increased the recursion threshold for CompareValueComplexity from 2 to 32. This change reverses that change by introducing a separate flag for CompareValueComplexity's threshold. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_40@297164 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 2 years ago
2 changed file(s) with 48 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
126126 cl::desc("Threshold for inlining multiplication operands into a SCEV"),
127127 cl::init(1000));
128128
129 static cl::opt
130 MaxCompareDepth("scalar-evolution-max-compare-depth", cl::Hidden,
131 cl::desc("Maximum depth of recursive compare complexity"),
132 cl::init(32));
129 static cl::opt MaxSCEVCompareDepth(
130 "scalar-evolution-max-scev-compare-depth", cl::Hidden,
131 cl::desc("Maximum depth of recursive SCEV complexity comparisons"),
132 cl::init(32));
133
134 static cl::opt MaxValueCompareDepth(
135 "scalar-evolution-max-value-compare-depth", cl::Hidden,
136 cl::desc("Maximum depth of recursive value complexity comparisons"),
137 cl::init(2));
133138
134139 //===----------------------------------------------------------------------===//
135140 // SCEV class definitions
480485 CompareValueComplexity(SmallSet, 8> &EqCache,
481486 const LoopInfo *const LI, Value *LV, Value *RV,
482487 unsigned Depth) {
483 if (Depth > MaxCompareDepth || EqCache.count({LV, RV}))
488 if (Depth > MaxValueCompareDepth || EqCache.count({LV, RV}))
484489 return 0;
485490
486491 // Order pointer values after integer values. This helps SCEVExpander form
567572 if (LType != RType)
568573 return (int)LType - (int)RType;
569574
570 if (Depth > MaxCompareDepth || EqCacheSCEV.count({LHS, RHS}))
575 if (Depth > MaxSCEVCompareDepth || EqCacheSCEV.count({LHS, RHS}))
571576 return 0;
572577 // Aside from the getSCEVType() ordering, the particular ordering
573578 // isn't very important except that it's beneficial to be consistent,
464464 });
465465 }
466466
467 TEST_F(ScalarEvolutionsTest, SCEVCompareComplexity) {
467 TEST_F(ScalarEvolutionsTest, CompareSCEVComplexity) {
468468 FunctionType *FTy =
469469 FunctionType::get(Type::getVoidTy(Context), std::vector(), false);
470470 Function *F = cast(M.getOrInsertFunction("f", FTy));
531531 EXPECT_NE(nullptr, SE.getSCEV(Acc[0]));
532532 }
533533
534 TEST_F(ScalarEvolutionsTest, CompareValueComplexity) {
535 IntegerType *IntPtrTy = M.getDataLayout().getIntPtrType(Context);
536 PointerType *IntPtrPtrTy = IntPtrTy->getPointerTo();
537
538 FunctionType *FTy =
539 FunctionType::get(Type::getVoidTy(Context), {IntPtrTy, IntPtrTy}, false);
540 Function *F = cast(M.getOrInsertFunction("f", FTy));
541 BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", F);
542
543 Value *X = &*F->arg_begin();
544 Value *Y = &*std::next(F->arg_begin());
545
546 const int ValueDepth = 10;
547 for (int i = 0; i < ValueDepth; i++) {
548 X = new LoadInst(new IntToPtrInst(X, IntPtrPtrTy, "", EntryBB), "",
549 /*isVolatile*/ false, EntryBB);
550 Y = new LoadInst(new IntToPtrInst(Y, IntPtrPtrTy, "", EntryBB), "",
551 /*isVolatile*/ false, EntryBB);
552 }
553
554 auto *MulA = BinaryOperator::CreateMul(X, Y, "", EntryBB);
555 auto *MulB = BinaryOperator::CreateMul(Y, X, "", EntryBB);
556 ReturnInst::Create(Context, nullptr, EntryBB);
557
558 // This test isn't checking for correctness. Today making A and B resolve to
559 // the same SCEV would require deeper searching in CompareValueComplexity,
560 // which will slow down compilation. However, this test can fail (with LLVM's
561 // behavior still being correct) if we ever have a smarter
562 // CompareValueComplexity that is both fast and more accurate.
563
564 ScalarEvolution SE = buildSE(*F);
565 auto *A = SE.getSCEV(MulA);
566 auto *B = SE.getSCEV(MulB);
567 EXPECT_NE(A, B);
568 }
569
534570 } // end anonymous namespace
535571 } // end namespace llvm