[PATCH] D54713: [SCEV] Guard movement of insertion point for loop-invariants

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 28 20:49:18 PST 2018


mkazantsev added a comment.

To clarify my comment about test: I've given an example of how it conceptually should look. Unit tests provide you opportunity to construct exactly the CFG you want, not relying on what opt, clang or some canonicalization passes are doing. If you take a look at `unittests/Analysis/ScalarEvolutionTest.cpp`, there are examples of that:

  // Check that SCEV does not save the SCEV -> V
  // mapping of SCEV differ from V in NSW flag.
  TEST_F(ScalarEvolutionsTest, SCEVCacheNSW) {
    /*
     * Create the following code:
     * func(i64 %a)
     * entry:
     *  %s1 = add i64 %a, -1
     *  %s2 = add nsw i64 %a, -1
     *  br label %exit
     * exit:
     *  ret %s
     */
  
    // Create a module.
    Module M("SCEVCacheNUW", Context);
  
    Type *T_int64 = Type::getInt64Ty(Context);
  
    FunctionType *FTy =
        FunctionType::get(Type::getVoidTy(Context), { T_int64 }, false);
    Function *F = cast<Function>(M.getOrInsertFunction("func", FTy));
    Argument *Arg = &*F->arg_begin();

...

You can construct the loop without preheader in this way. You can then explicitly ask expander to expand something to the point you want (there are examples of that in this file).

I am OK if you merge this patch as is under condition that you will later construct the unit test for non-preheader case, and if it will fail, fix it as well.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54713/new/

https://reviews.llvm.org/D54713





More information about the llvm-commits mailing list