[llvm-dev] [cfe-dev] [RFC] Loading Bitfields with Smallest Needed Types

Carrot Wei via llvm-dev llvm-dev at lists.llvm.org
Wed May 27 10:04:32 PDT 2020


> Similar issue with aligned extload widening. The load and store are both
> i16 in IR.

> struct s {
> int x; // force alignment
> short y;
> };

> void g();
> short f2(s *a, short b) {
> a->y = b;
> g();
> return a->y - b;
> }

> produces this
> movq %rdi, %rbx
> movw %bp, 4(%rdi) // 2 byte store
> callq g()
> movl 4(%rbx), %eax // 4 byte load
> subl %ebp, %eax

> ~Craig


It is caused by loadi32:


def loadi32 : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)), [{
  LoadSDNode *LD = cast<LoadSDNode>(N);
  ISD::LoadExtType ExtType = LD->getExtensionType();
  if (ExtType == ISD::NON_EXTLOAD)
    return true;
  if (ExtType == ISD::EXTLOAD)                                  // *
    return LD->getAlignment() >= 4 && LD->isSimple();           // *
  return false;
}]>;


Without the commented lines, movzwl should be generated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200527/28813681/attachment.html>


More information about the llvm-dev mailing list