# [PATCH] Alignment assumptions using invariants

Andrew Trick atrick at apple.com
Thu Sep 4 20:13:44 PDT 2014

```>I think that SCEV is the right thing to use here. In the line you have
>above, for example, the subtraction will in general be two linear
>recurrences, and we want to know if they have a constant
>difference. There are a lot of potential special cases that could be
>done more efficiently, but I'm not sure that is worthwhile (in this
>case, for example, I think the preceding division is more expensive
>regardless).

Ok. My point here was that it looks like getNewAlignmentDiff only works (only reduces to a constant) if both DiffSCEV and AlignSCEV are constants to begin with. In that case, just extract the constants first, and don't bother with SCEV at this particular point.

================
Comment at: lib/Transforms/Scalar/AlignmentFromAssumptions.cpp:362
@@ +361,3 @@
+
+        // If these four alignments, pick the largest possible...
+        unsigned NewAlignment = 0;
----------------
"Of these four"

================
Comment at: lib/Transforms/Scalar/AlignmentFromAssumptions.cpp:393-397
@@ +392,7 @@
+    // the pointer to update.
+    Visited.insert(J);
+    for (User *UJ : J->users()) {
+      Instruction *K = cast<Instruction>(UJ);
+      if (!Visited.count(K) && isValidAssumeForContext(I, K, DL, DT))
+        WorkList.push_back(K);
+    }
----------------
To avoid redundant worklist entries why not this:

for (User *UJ : J->users()) {
Instruction *K = cast<Instruction>(UJ);
if (Visited.insert(K) && isValidAssumeForContext(I, K, DL, DT))
WorkList.push_back(K);

nit: it's a little hard to guess what 'I' means this far away from where it is declared as an argument. 'AssumptionCall'?

http://reviews.llvm.org/D181

```