[PATCH] D46414: [GlobalISel][Legalizer] More concise and faster widenScalar, NFC

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 8 16:57:46 PDT 2018


dsanders added a comment.

> Yes, I do have my doubts that the original implementation with sign extension is always correct, but it's NFC here anyway. I'm thinking to take a look at it at some point and see if I can come up with a breaking test case for that sign extend.

This should be ok. It's really an any-extend until another MI forces it one way or the other. Suppose we have:

  %0:_(s32) = G_CONSTANT i32 ...
  %1:_(s32) = G_OPCODE %0

after widening G_CONSTANT we get:

  %0:_(s64) = G_CONSTANT i64 anyext_from_i32(...)
  %1:_(s32) = G_TRUNC %0
  %2:_(s32) = G_OPCODE %1

When we legalize G_OPCODE we get one of the following cases:
It consumes the original type, leaving the truncate and removing the undefined bits:

  %0:_(s64) = G_CONSTANT i64 anyext_from_i32(...)
  %1:_(s32) = G_TRUNC %0
  %2:_(s32) = G_OPCODE %1

It widens and doesn't care about the excess bits:

  %0:_(s64) = G_CONSTANT i64 anyext_from_i32(...)
  %1:_(s32) = G_TRUNC %0
  %2:_(s64) = G_ANYEXT %1
  %2:_(s64) = G_OPCODE %2

which simplifies to:

  %0:_(s64) = G_CONSTANT i64 anyext_from_i32(...)
  %2:_(s64) = G_OPCODE %0

It widens and does care about the excess bits:

  %0:_(s64) = G_CONSTANT i64 anyext_from_i32(...)
  %1:_(s32) = G_TRUNC %0
  %2:_(s64) = G_SEXT %1
  %2:_(s64) = G_OPCODE %2

which simplifies to:

  %0:_(s64) = G_CONSTANT i64 signext_from_i32(...)
  %2:_(s64) = G_OPCODE %0

The narrowScalar case is a mixture of the two. The portions that correspond solely to extension bits end up dead and removed while the portions that partially correspond to both extension bits and value bits act like widenScalar


Repository:
  rL LLVM

https://reviews.llvm.org/D46414





More information about the llvm-commits mailing list