[LLVMdev] Some positive feedback :)

Talin viridia at gmail.com
Mon May 5 01:16:35 PDT 2008


Chris Lattner wrote:
> On Apr 30, 2008, at 9:42 PM, Talin wrote:
>   
>> I continue to be pleasantly surprised at how well LLVM works. Working
>> with it is certainly a treat.
>>     
>
>   
>> After making a few tweaks to my code generator, it passed all of the
>> tests...which was surprising enough. But then I turned on optimization
>> -- and lo and behold, it converted every one of those asserts to  
>> "assert(1)", and completely eliminated everything else! If it had been
>> able to inline the asserts (which I am still working on), it would  
>> have
>> eliminated the body of main entirely.
>>
>> Now that's the kind of optimization I like to see :)
>>     
>
> Awesome!
>   
Here's another code sample that boils down to "assert(true)" when 
optimization is turned on:

    struct CountIterator(Iterator<int>) {
      private var count:int;
      def CountIterator(count:int) { self.count = count; }
      def atEnd:bool { get { return count <= 0; } }
      def current:int { get { return count; } }
      def next() { --count; }
    }

    def testSimpleIterator() {
      var sum = 0;
      for i in CountIterator(5) {
        sum = sum + i;
      }
     
      assert(sum == 15);
    }

-- Talin




More information about the llvm-dev mailing list