Stream: t-compiler/wg-llvm

Topic: Stack alignment in leaf function

ecstatic-morse (Oct 23 2019 at 18:34, on Zulip):

Why does LLVM emit a push/pop for this example? I posted a half-baked theory, but I don't have very much experience with LLVM. Obviously this isn't a huge deal, just curious.

rkruppe (Oct 23 2019 at 18:46, on Zulip):

I am pretty sure your theory is false. -Cllvm-args=-print-after-all shows that the final IR before instruction selection has no calls (though it has a bunch of loads, stores, and compares that should have been constant folded) and the MachineIR is just "ret 1" aside from debuginfo

rkruppe (Oct 23 2019 at 18:51, on Zulip):

Oh no, the MIR also has stack slots allocated, even though they are dead. That might have something to do with it?

rkruppe (Oct 23 2019 at 18:51, on Zulip):
# *** IR Dump After Finalize ISel and expand pseudo-instructions ***:
# Machine code for function _RNvCsbDqzXfLQacH_7example7compare: IsSSA, TracksLiveness
Frame Objects:
  fi#0: size=4, align=1, at location [SP+8]
  fi#1: size=4, align=4, at location [SP+8]

bb.0 (%ir-block.0):
  LIFETIME_END %stack.1
  LIFETIME_END %stack.0
  %0:gr8 = MOV8ri 1
  $al = COPY %0:gr8
  RET 0, $al
rkruppe (Oct 23 2019 at 18:52, on Zulip):

(this is with -Cdebuginfo=0)

Nikita Popov (Oct 23 2019 at 19:00, on Zulip):

LLVM expands memcmp/bcmp in the ExpandMemcmp pass prior to SDAG lowering. As this happens very late, there's no opportunity for general combining passes (like InstCombine) to run anymore. The simplification happens in DAGCombine, which is not able to eliminate those ligetime.start/end pairs.

Nikita Popov (Oct 23 2019 at 19:02, on Zulip):

I think there were some plans to move this expansion into the opt pipeline...

Nikita Popov (Oct 23 2019 at 19:04, on Zulip):

Indeed: Looks like it got applied + reverted two times.

rkruppe (Oct 23 2019 at 19:05, on Zulip):


Last update: Jul 03 2020 at 16:45UTC