[PATCH] D18777: [ValueTracking] An improvement to IR ValueTracking on Non-negative Integers

Mitch Bodart via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 15 16:20:55 PDT 2016


mbodart added inline comments.

================
Comment at: lib/Analysis/ValueTracking.cpp:817
@@ +816,3 @@
+        KnownZero |= APInt::getSignBit(BitWidth);
+    if (KnownOne2.isNegative())
+        KnownOne |= APInt::getSignBit(BitWidth);
----------------
This could be an "else if", as the sign bit cannot be both known 0 and known 1.

================
Comment at: lib/Analysis/ValueTracking.cpp:1301
@@ +1300,3 @@
+
+            if (Opcode == Instruction::Sub && KnownZero3.isNegative() && 
+                KnownOne2.isNegative())
----------------
For the Sub case we have to be more careful about which value is the LHS and which is the RHS.
The way the code is currently structured, if (LL == I) then R is the LHS and L is the RHS,
otherwise vice versa.  So we have to take (LL == I) into account to know whether to
check (KnownZero3, KnownOne2) or (KnownZero2, KnownOne3).

And while I don't know how valuable it would be to catch additional cases, we could set a KnownOne sign bit result for the Sub case if it's (negative -= non-negative), and for the Add case if it's (negative += negative).

================
Comment at: test/Analysis/ValueTracking/known-non-negative.ll:6
@@ +5,3 @@
+; CHECK-LABEL: @test_indvar_nonnegative(
+; CHECK: br i1 true, label %for.end, label %for.body
+entry:
----------------
Please add additional test cases for mul and sub.


http://reviews.llvm.org/D18777





More information about the llvm-commits mailing list