[PATCH] [ValueTracking] do not overwrite analysis results already computed

Jingyue Wu jingyue at google.com
Wed Jun 10 23:03:12 PDT 2015


How about this patch? It is equivalent to the old patch but requires much less
source code modification.

The old patch writes the known bits computed from arithmetics (the big switch
starting from around L1080) to KnownZero1/2 and KnownOne1/2 locally, and updates
KnownZero and KnownOne afterwards.

The new patch saves KnownOne and KnownZero before the switch, and later merges
the saved results with the known bits computed from arithmetics.

I am fine with either approach. I slightly prefer the first one because
KnownOne and KnownZero consistently holds everything ValueTracking knows so
far. But the second approach requires less source code change.


http://reviews.llvm.org/D10283

Files:
  lib/Analysis/ValueTracking.cpp
  test/Analysis/ValueTracking/assume.ll

Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -1071,12 +1071,16 @@
   // Check whether there's a dominating condition which implies something about
   // this value at the given context.
   if (EnableDomConditions && Depth <= DomConditionsMaxDepth)
+    // FIXME: this call may overwrite the known bits computed from assumes.
     computeKnownBitsFromDominatingCondition(V, KnownZero, KnownOne, DL, Depth,
                                             Q);
 
   Operator *I = dyn_cast<Operator>(V);
   if (!I) return;
 
+  // Save KnownZero and KnownOne so that they won't be overwritten by the
+  // following computeKnownBits calls.
+  APInt SavedKnownZero(KnownZero), SavedKnownOne(KnownOne);
   APInt KnownZero2(KnownZero), KnownOne2(KnownOne);
   switch (I->getOpcode()) {
   default: break;
@@ -1523,6 +1527,8 @@
       }
     }
   }
+  KnownZero |= SavedKnownZero;
+  KnownOne |= SavedKnownOne;
 
   assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?");
 }
Index: test/Analysis/ValueTracking/assume.ll
===================================================================
--- /dev/null
+++ test/Analysis/ValueTracking/assume.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i32 @assume_add(i32 %a, i32 %b) {
+; CHECK-LABEL: @assume_add(
+  %1 = add i32 %a, %b
+  %last_two_digits = and i32 %1, 3
+  %2 = icmp eq i32 %last_two_digits, 0
+  call void @llvm.assume(i1 %2)
+  %3 = add i32 %1, 3
+; CHECK: %3 = or i32 %1, 3
+  ret i32 %3
+}
+
+declare void @llvm.assume(i1)

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10283.27486.patch
Type: text/x-patch
Size: 1653 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150611/07f56097/attachment.bin>


More information about the llvm-commits mailing list