[PATCH] D47928: [SimplifyIndVars] Eliminate redundant truncs
Philip Reames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 13 11:20:52 PDT 2018
reames added a comment.
Thinking about this further, I see another opportunity for a follow on improvement, sketched below in comments.
================
Comment at: test/Transforms/IndVarSimplify/eliminate-trunc.ll:157
+loop:
+ %iv = phi i64 [ -2147483648, %entry ], [ %iv.next, %loop ]
+ %iv.next = add i64 %iv, 1
----------------
I think the same basic logic as sketched for the other LFTR problem works here as well. Just with a [SINT_MIN, SINT_MAX-1] initial range for IV.
================
Comment at: test/Transforms/IndVarSimplify/eliminate-trunc.ll:242
+ br i1 %cmp, label %loop, label %exit
+exit:
+ ret void
----------------
I think this case is actually something missing in SCEV. Let me walk through the logic by which we should be able to handle this.
IV is known to be [0, UINT32_MAX-1] inclusive - since it must be less than some value %n and the trunc doesn't change behavior before that point.
Thus, IV + 1 is known to not nuw wrap in the 32 bit domain.
Thus, trunc(IV+1) doesn't loose any bits.
Thus zext(trunc(IV+1)) == IV+1.
I think we're probably missing a range check somewhere inside the getZeroExt routine.
Note this logic only works for strict less than. Doing it for ule wouldn't work.
https://reviews.llvm.org/D47928
More information about the llvm-commits
mailing list