{"action":"created","issue":{"url":"https://api.github.com/repos/kripken/emscripten/issues/3233","labels_url":"https://api.github.com/repos/kripken/emscripten/issues/3233/labels{/name}","comments_url":"https://api.github.com/repos/kripken/emscripten/issues/3233/comments","events_url":"https://api.github.com/repos/kripken/emscripten/issues/3233/events","html_url":"https://github.com/kripken/emscripten/issues/3233","id":60113009,"number":3233,"title":"Better variable elimination?","user":{"login":"waywardmonkeys","id":178582,"avatar_url":"https://avatars.githubusercontent.com/u/178582?v=3","gravatar_id":"","url":"https://api.github.com/users/waywardmonkeys","html_url":"https://github.com/waywardmonkeys","followers_url":"https://api.github.com/users/waywardmonkeys/followers","following_url":"https://api.github.com/users/waywardmonkeys/following{/other_user}","gists_url":"https://api.github.com/users/waywardmonkeys/gists{/gist_id}","starred_url":"https://api.github.com/users/waywardmonkeys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/waywardmonkeys/subscriptions","organizations_url":"https://api.github.com/users/waywardmonkeys/orgs","repos_url":"https://api.github.com/users/waywardmonkeys/repos","events_url":"https://api.github.com/users/waywardmonkeys/events{/privacy}","received_events_url":"https://api.github.com/users/waywardmonkeys/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-06T15:06:20Z","updated_at":"2015-03-07T03:47:53Z","closed_at":null,"body":"Taking this code as an example:\r\n\r\n````javascript\r\nfunction __ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4findEcj($this, $__c) {\r\n $this = $this | 0;\r\n $__c = $__c | 0;\r\n var $$0$i = 0, $0 = 0, $11 = 0, $13 = 0, $14 = 0, sp = 0;\r\n sp = STACKTOP;\r\n $0 = HEAP8[$this >> 0] | 0;\r\n if (!($0 & 1)) {\r\n  $11 = ($0 & 255) >>> 1;\r\n  $13 = $this + 1 | 0;\r\n } else {\r\n  $11 = HEAP32[$this + 4 >> 2] | 0;\r\n  $13 = HEAP32[$this + 8 >> 2] | 0;\r\n }\r\n if (!$11) {\r\n  $$0$i = -1;\r\n  STACKTOP = sp;\r\n  return $$0$i | 0;\r\n }\r\n $14 = _memchr($13, $__c & 255, $11) | 0;\r\n if (!$14) {\r\n  $$0$i = -1;\r\n  STACKTOP = sp;\r\n  return $$0$i | 0;\r\n }\r\n $$0$i = $14 - $13 | 0;\r\n STACKTOP = sp;\r\n return $$0$i | 0;\r\n}\r\n````\r\n\r\nWe're running the aggressive variable elimination and registerize-harder ...\r\n\r\nCan't it get rid of ``$$0$i``?\r\n"},"comment":{"url":"https://api.github.com/repos/kripken/emscripten/issues/comments/77671700","html_url":"https://github.com/kripken/emscripten/issues/3233#issuecomment-77671700","issue_url":"https://api.github.com/repos/kripken/emscripten/issues/3233","id":77671700,"user":{"login":"kripken","id":173661,"avatar_url":"https://avatars.githubusercontent.com/u/173661?v=3","gravatar_id":"","url":"https://api.github.com/users/kripken","html_url":"https://github.com/kripken","followers_url":"https://api.github.com/users/kripken/followers","following_url":"https://api.github.com/users/kripken/following{/other_user}","gists_url":"https://api.github.com/users/kripken/gists{/gist_id}","starred_url":"https://api.github.com/users/kripken/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kripken/subscriptions","organizations_url":"https://api.github.com/users/kripken/orgs","repos_url":"https://api.github.com/users/kripken/repos","events_url":"https://api.github.com/users/kripken/events{/privacy}","received_events_url":"https://api.github.com/users/kripken/received_events","type":"User","site_admin":false},"created_at":"2015-03-07T03:47:53Z","updated_at":"2015-03-07T03:47:53Z","body":"The eliminator and aggressive variable elimination focus on single-assignment variables. $$0$i isn't single-assignment because the block was split in the relooper (we split return blocks sometimes); also it appears to be a phi variable? Although that part looks odd. Seeing the LLVM IR would clarify.\r\n\r\nRegisterize harder wasn't run on this code yet, I believe? Not that it would help.\r\n\r\nTo get this to be eliminated, it would need to be split into several single-assignment variables. But the main issue is that the relooper is spilling the return block - if you really want to reduce code size, you don't want that, even if it runs a little slower due to `label` variable usage. If that sounds interesting to you, I could make `-Os/-Oz` during link disable splitting in the relooper.\r\n\r\nA separate issue is that what's going on with the phi here. Might be clearer without splitting."}}