[PATCH] fix for PR16393: miscompile with struct byval

Manman Ren mren at apple.com
Tue Jul 2 17:19:03 PDT 2013


For a call site with struct byval, we will generate a sequence of instructions: STACKDOWN, STRUCT_BYVAL and STACKUP.
STRUCT_BYVAL later on is expanded to a for loop. This caused issue in PEI when trying to eliminate frame indices.

BB1:
  STACKDOWN
BB2:
  memcpy
BB3:
  STACKUP

PEI currently assumes SPAdj is 0 at the beginning of a basic block, but this is not true for BB2 or BB3. The proposed patch tries
to fix the problem by inserting SET_SP_ADJ in BB2 and BB3:
BB1:
  STACKDOWN
BB2:
  SET_SP_ADJ
  memcpy
BB3:
  SET_SP_ADJ
  STACKUP

A target-independent opcode SET_SP_ADJ is introduced, and pseudo instruction STRUCT_BYVAL is modified to take one extra
argument (the amount of SP Adjustment). When we are expanding STRUCT_BYVAL to a for loop, we add SET_SP_ADJ to BB2 and BB3.

PEI is also modified to handle SET_SP_ADJ. To make sure SET_SP_ADJ is always before any spill code that references frame indices,
SET_SP_ADJ is treated as a label.

SET_SP_ADJ can be useful for other targets when STACKDOWN and STACKUP are not paired up in the same basic block.

Comments and other suggestions are welcome.

Thanks,
Manman
-------------- next part --------------
A non-text attachment was scrubbed...
Name: byval_spadj_2.patch
Type: application/octet-stream
Size: 41463 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130702/2b00620d/attachment.obj>


More information about the llvm-commits mailing list