<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>playing with pointers</title>
    <description>Sanjoy Das, Software Engineer. Blog on compilers, computer science, math, programming, virtual machines.
</description>
    <link>http://playingwithpointers.com/</link>
    <atom:link href="http://playingwithpointers.com/feed.xml" rel="self" type="application/rss+xml" />
    <pubDate>Sun, 09 Jan 2022 14:34:55 -0800</pubDate>
    <lastBuildDate>Sun, 09 Jan 2022 14:34:55 -0800</lastBuildDate>
    <generator>Jekyll v4.2.1</generator>
    
    
      <item>
        <title>Understanding Ladner's Theorem</title>
        <description>&lt;p&gt;As you probably know, whether \(P = NP\) is a &lt;a href=&quot;https://en.wikipedia.org/wiki/P_versus_NP_problem&quot;&gt;major unsolved problem&lt;/a&gt; in computer science.&lt;/p&gt;

&lt;p&gt;Even if you believe \(P \ne NP\), it is tempting to think that &lt;em&gt;NP&lt;/em&gt; \(=\) &lt;em&gt;P&lt;/em&gt; \(\cup\) &lt;em&gt;NP&lt;/em&gt;-complete – that every problem in &lt;em&gt;NP&lt;/em&gt; can either be solved in polynomial time or is expressive enough to encode &lt;em&gt;SAT&lt;/em&gt;.&lt;/p&gt;
</description>
        <pubDate>Thu, 07 May 2020 00:00:00 -0700</pubDate>
        <link>http://playingwithpointers.com/blog/ladners-theorem.html</link>
        <guid isPermaLink="true">http://playingwithpointers.com/blog/ladners-theorem.html</guid>
        
        
      </item>
    
      <item>
        <title>Seemingly Impossible Turing Machines</title>
        <description>&lt;p&gt;In this post I’ll explore a concept I discovered in a &lt;a href=&quot;http://math.andrej.com/2007/09/28/seemingly-impossible-functional-programs/&quot;&gt;very interesting writeup&lt;/a&gt; by Martin Escardo on Andrej Bauer’s blog.  The title of this post is an homage to the title used by Martin Escardo: “Seemingly impossible functional programs”.&lt;/p&gt;

&lt;p&gt;I have made the following changes from the original post:&lt;/p&gt;
</description>
        <pubDate>Sat, 29 Jun 2019 00:00:00 -0700</pubDate>
        <link>http://playingwithpointers.com/blog/impossible-programs.html</link>
        <guid isPermaLink="true">http://playingwithpointers.com/blog/impossible-programs.html</guid>
        
        
      </item>
    
      <item>
        <title>Resource Variable Operations in TensorFlow/XLA</title>
        <description>&lt;p&gt;In this post we will look at how we auto-cluster resource variable operations in TensorFlow graphs into XLA computations and why it isn’t entirely trivial.&lt;/p&gt;

&lt;h1 id=&quot;a-word-about-tensors&quot;&gt;A Word About Tensors&lt;/h1&gt;

&lt;p&gt;Tensors in TensorFlow are represented as instances (surprise!) of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tensor&lt;/code&gt; &lt;a href=&quot;https://github.com/tensorflow/tensorflow/blob/a0a971bcda3dc2fc2fdcae0a29d5a53f82e6d64f/tensorflow/core/framework/tensor.h#L58&quot;&gt;class&lt;/a&gt;.  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tensor&lt;/code&gt; instances contain information about the shape of a tensor and a pointer to a reference counted buffer, which is an instance of  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TensorBuffer&lt;/code&gt;.  Multiple instance of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tensor&lt;/code&gt; can point to the same &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TensorBuffer&lt;/code&gt;.&lt;/p&gt;
</description>
        <pubDate>Fri, 21 Jun 2019 00:00:00 -0700</pubDate>
        <link>http://playingwithpointers.com/blog/auto-clustering-resource-vars.html</link>
        <guid isPermaLink="true">http://playingwithpointers.com/blog/auto-clustering-resource-vars.html</guid>
        
        
      </item>
    
      <item>
        <title>Control Flow in TensorFlow &amp; XLA's Auto-Clustering</title>
        <description>&lt;p&gt;In this post we’ll look at an interesting issue that crops up when auto-clustering TensorFlow graphs.  I’ve deliberately focused more on the problem than on the solution – the possible solutions are, in my opinion, fairly obvious once the problem is clear.&lt;/p&gt;

&lt;h1 id=&quot;control-flow-in-tensorflow&quot;&gt;Control flow in TensorFlow&lt;/h1&gt;

&lt;p&gt;First we need a high level overview of how control flow is represented in TensorFlow graphs.&lt;/p&gt;
</description>
        <pubDate>Sun, 07 Oct 2018 00:00:00 -0700</pubDate>
        <link>http://playingwithpointers.com/blog/control-flow-and-tf-xla.html</link>
        <guid isPermaLink="true">http://playingwithpointers.com/blog/control-flow-and-tf-xla.html</guid>
        
        
      </item>
    
      <item>
        <title>An Issue with Java's Final Fields</title>
        <description>&lt;p&gt;I believe the current specification of final fields in the Java Memory
Model is broken in one of the following ways:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;It prevents some basic CSE-type compiler-optimizations&lt;/li&gt;
  &lt;li&gt;It requires the JVM to make every load an acquire load&lt;/li&gt;
  &lt;li&gt;It complicates compiler IR by forcing it to track syntactic
dependencies&lt;/li&gt;
  &lt;li&gt;It requires weakening the JMM in a backward incompatible way&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While this isn’t exactly news (I have been told that the wording
around final fields in the JMM is known to be problematic), I could
not easily find an explicit record of this issue anywhere else on the
internet.  Hence this blog post.&lt;/p&gt;
</description>
        <pubDate>Tue, 21 Mar 2017 00:00:00 -0700</pubDate>
        <link>http://playingwithpointers.com/blog/jmm-finals-issue.html</link>
        <guid isPermaLink="true">http://playingwithpointers.com/blog/jmm-finals-issue.html</guid>
        
        
      </item>
    
      <item>
        <title>Integer overflow in LLVM's ScalarEvolution</title>
        <description>&lt;p&gt;&lt;em&gt;This is a short note on how integer overflow fits in with LLVM’s
ScalarEvolution.  This post is specific to LLVM’s implementation of
ScalarEvolution, and I’ve assumed some familiarity with LLVM internals
and integer arithmetic.&lt;/em&gt;&lt;/p&gt;

&lt;h1 id=&quot;scalarevolution-and-add-recurrences&quot;&gt;ScalarEvolution and add recurrences&lt;/h1&gt;

&lt;p&gt;ScalarEvolution is an analysis in LLVM&lt;sup id=&quot;fnref:scevextra&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:scevextra&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; that helps its
clients reason about induction variables.  It does this by
mapping&lt;sup id=&quot;fnref:lazy&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:lazy&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt; SSA values into objects of a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SCEV&lt;/code&gt; type, and
implementing an algebra on top of it.  Using this algebra, clients of
ScalarEvolution can ask questions like “is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A&lt;/code&gt; always signed-less-than
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;B&lt;/code&gt;?” or “is the difference between &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;B&lt;/code&gt; a constant integer?”,
where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;B&lt;/code&gt; are objects of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SCEV&lt;/code&gt; data type.&lt;/p&gt;
</description>
        <pubDate>Sun, 18 Sep 2016 00:00:00 -0700</pubDate>
        <link>http://playingwithpointers.com/blog/scev-integer-overflow.html</link>
        <guid isPermaLink="true">http://playingwithpointers.com/blog/scev-integer-overflow.html</guid>
        
        
      </item>
    
      <item>
        <title>Inter-Procedural Optimization and Derefinement</title>
        <description>&lt;p&gt;&lt;em&gt;This is a summary of an issue that was semi-recently fixed in
&lt;a href=&quot;http://llvm.org/PR26774&quot;&gt;LLVM&lt;/a&gt; and
&lt;a href=&quot;https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70018&quot;&gt;GCC&lt;/a&gt;.  It merits
a blog post because the issue is somewhat subtle, and a central place
to refer to can be helpful.&lt;/em&gt;&lt;/p&gt;

&lt;h1 id=&quot;setting-the-stage&quot;&gt;Setting the Stage&lt;/h1&gt;

&lt;p&gt;In this post we will focus on C++ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inline&lt;/code&gt; functions.  The problem
described here may apply to other cases as well, but we won’t focus on
those.&lt;/p&gt;
</description>
        <pubDate>Sat, 16 Jul 2016 00:00:00 -0700</pubDate>
        <link>http://playingwithpointers.com/blog/ipo-and-derefinement.html</link>
        <guid isPermaLink="true">http://playingwithpointers.com/blog/ipo-and-derefinement.html</guid>
        
        
      </item>
    
      <item>
        <title>Check Widening in LLVM</title>
        <description>&lt;p&gt;&lt;em&gt;This post describes infrastructure that has gone in to LLVM piecemeal
over the last couple of months.  All of the information in this post
is scattered throughout in commit messages on
&lt;a href=&quot;http://lists.llvm.org/pipermail/llvm-commits/&quot;&gt;llvm-commits&lt;/a&gt; and
email threads on
&lt;a href=&quot;http://lists.llvm.org/pipermail/llvm-dev/&quot;&gt;llvm-dev&lt;/a&gt;.  This post is
intended to present a coherent story for people not actively involved
in the original discussions and without the spare time to stitch
together the big picture from individual commits and emails.&lt;/em&gt;&lt;/p&gt;

&lt;h1 id=&quot;motivation-checks-in-managed-languages&quot;&gt;Motivation: Checks in Managed Languages&lt;/h1&gt;

&lt;p&gt;In “safe” languages like Java, it is the virtual machine’s job to
ensure that illegal operations (like dereferencing bad memory or
unsound type coercions) does not lead to the program into arbitrarily
bad states.  This is typically enforced by adding runtime checks to
certain operations to check for violations.  Field accesses elicit a
null check, array loads and stores have a range check (and in some
cases a type check), type casts check the cast is well-formed etc.
For this post we’ll focus on range checks only, but the general idea
is applicable to any kind of runtime check.&lt;/p&gt;
</description>
        <pubDate>Fri, 17 Jun 2016 00:00:00 -0700</pubDate>
        <link>http://playingwithpointers.com/blog/check-widening.html</link>
        <guid isPermaLink="true">http://playingwithpointers.com/blog/check-widening.html</guid>
        
        
      </item>
    
      <item>
        <title>A Problem with LLVM's Undef</title>
        <description>&lt;p&gt;LLVM has a special value in its SSA value hierarchy called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undef&lt;/code&gt;
that is used to model (amongst other things) reads from uninitialized
memory.  Semantically, an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undef&lt;/code&gt; value has a potentially new bit
pattern of the compiler’s choosing at each &lt;em&gt;use site&lt;/em&gt;, meaning that
values like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;xor i32 %a, %a&lt;/code&gt; need not always evaluate to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt; when
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%a&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undef&lt;/code&gt; (even though they’re allowed to).  This lack of
consistency lets LLVM get away without allocating registers to
remember a specific “version” of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undef&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Another way to look at this is that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undef&lt;/code&gt; isn’t a normal SSA value,
and &lt;em&gt;uses&lt;/em&gt; of an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undef&lt;/code&gt; value are also its &lt;em&gt;defs&lt;/em&gt;.  This leads to
some interesting restrictions on data flow analysis via control flow,
and, in some cases, accounting for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undef&lt;/code&gt; inhibits optimization
instead of enabling it.&lt;/p&gt;
</description>
        <pubDate>Tue, 29 Dec 2015 00:00:00 -0800</pubDate>
        <link>http://playingwithpointers.com/blog/problem-with-undef.html</link>
        <guid isPermaLink="true">http://playingwithpointers.com/blog/problem-with-undef.html</guid>
        
        
      </item>
    
      <item>
        <title>Reference Counting: Harder than it Sounds</title>
        <description>&lt;p&gt;Naive reference counting is “easy” to implement on a system that does
not share objects between threads, but thinking about reference
counting in systems that &lt;strong&gt;do&lt;/strong&gt; share objects between threads, two
problems (other than the standard “increments and decrements need to
be atomic operations”) come to mind.  So far the contents of this post
(which are &lt;strong&gt;not&lt;/strong&gt; novel) have lived in one-off tweets and emails, but
I think it is time to write them down in an organized way.&lt;/p&gt;

&lt;h1 id=&quot;problem-0-stores-to-the-heap-need-to-be-xchges&quot;&gt;Problem 0: Stores to the Heap need to be XCHGes&lt;/h1&gt;

&lt;p&gt;(Edit: I initially had a few mistakes here – I’d claimed that the
stores need to be CAS’es when an XCHG would be sufficient.  The order
between the increment and the decrement was also incorrect.  Thanks
&lt;a href=&quot;https://disqus.com/by/barrkel/&quot;&gt;@barrkel&lt;/a&gt; for pointing these out!)&lt;/p&gt;
</description>
        <pubDate>Wed, 14 Oct 2015 00:00:00 -0700</pubDate>
        <link>http://playingwithpointers.com/blog/refcounting-harder-than-it-sounds.html</link>
        <guid isPermaLink="true">http://playingwithpointers.com/blog/refcounting-harder-than-it-sounds.html</guid>
        
        
      </item>
    
  </channel>
</rss>
