I continue to be pleasantly surprised at how well LLVM works. Working with it is certainly a treat. As an example, tonight I implemented structure types (i.e. aggregate types that are passed as values, not references) in my front end, and I wrote up this little unit test: struct Vector { var x:int; var y:int; var z:int; def Vector(x:int, y:int, z:int) { self.x = x; self.y = y; self.z = z; } def Vector() { self.x = 0; self.y = 0; self.z = 0; } } [EntryPoint] def main(args:String[]) { var v0:Vector = Vector(); assert(v0.x == 0); assert(v0.y == 0); assert(v0.z == 0); let v1 = Vector(2, 3, 4); assert(v1.x == 2); assert(v1.y == 3); assert(v1.z == 4); v0 = v1; assert(v0.x == 2); assert(v0.y == 3); assert(v0.z == 4); } 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 :) -- Talin
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! -Chris
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
Possibly Parallel Threads
- [LLVMdev] Some positive feedback :)
- About scales in graphics
- Error at Pre-regalloc Machine LICM: "getVRegDef assumes a single definition or no definition"' failed.
- [LLVMdev] Rolling my own appending linkage
- [LLVMdev] Float compare-for-equality and select optimization opportunity