[PATCH] D18867: [IndVarSimplify] Eliminate zext of a signed IV when the IV is known to be non-negative

Li Huang via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 21 16:04:16 PDT 2016


lihuang updated this revision to Diff 54591.
lihuang added a comment.

Sorry for the late reply, took sick days.

I spent some time looking at the ScalarEvolution code. isKnownPredicate doesn't catch this case because when creating SCEV from an instruction, the "nsw" flag of the instruction is not propagated to the SCEV. For example, the case in the added test:

          %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
          ... 
          %add = add nsw i32 %i.0, 2
          ...
          %inc = add nsw i32 %i.0, 1
  		

When creating SCEV for %add from "%add = add nsw i32 %i.0, 2", the "nsw" flag is lost so it's not recognized as non-negative. The code that rules out this flag is in getNoWrapFlagsFromUB(), which is introduced in http://reviews.llvm.org/D11212 . I'm not very familiar with the SCEV code, so I'm not sure if the flag propagation in SCEV is supposed to propagate "nsw" in this case. If the flag propagation is correct, then we might need to use isKnownNonNegative from ValueTracking.

What do you suggest?


http://reviews.llvm.org/D18867

Files:
  lib/Transforms/Scalar/IndVarSimplify.cpp
  test/Transforms/IndVarSimplify/iv-sext.ll
  test/Transforms/IndVarSimplify/iv-zext.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18867.54591.patch
Type: text/x-patch
Size: 4749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160421/df87d82a/attachment.bin>


More information about the llvm-commits mailing list