[llvm-bugs] [Bug 37299] New: Duplicate constants in stack lowering

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Apr 30 20:01:11 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37299

            Bug ID: 37299
           Summary: Duplicate constants in stack lowering
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: WebAssembly
          Assignee: unassignedbugs at nondot.org
          Reporter: alonzakai at gmail.com
                CC: llvm-bugs at lists.llvm.org

The Souper superoptimizer finds stuff like this in the wasm backend's output, 

; start LHS (in $luaL_error)
%0:i32 = var
; (i32.sub(get_local $5)(i32.const 128))
%1 = sub %0, 128:i32
; (i32.add(get_local $3)(i32.const 128))
%2 = add %1, 128:i32
infer %2

which corresponds to wasm like this

 (func $luaL_error (; 41 ;) (type $3) (param $var$0 i32) (param $var$1 i32)
(param $var$2 i32) (result i32)
  (local $var$3 i32)
  (local $var$4 i32)
  (i32.store
   (i32.const 1024)
   (tee_local $var$3
    (i32.sub
     (i32.load
      (i32.const 1024)
     )
     (i32.const 128)
    )
   )
  )
  [..]
  (i32.store
   (i32.const 1024)
   (i32.add
    (get_local $var$3)
    (i32.const 128)
   )
  )
  (get_local $var$0)
 )

So it subs 128 from the stack pointer, then adds 128 to restore it. An
alternative would be to use a local to save the original value instead, which
would save a few bytes (avoid the add + constant at the end), although I'm not
sure how that would affect the size of the uses of the stack pointer in the
middle there.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180501/a30989ea/attachment.html>


More information about the llvm-bugs mailing list