[PATCH] D50623: [NFC] [Hexagon] Simplify int8 truncation and validation

Kim Gräsman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 13 06:38:05 PDT 2018


kimgr added inline comments.


================
Comment at: lib/Target/Hexagon/HexagonBitSimplify.cpp:1980
-    case Hexagon::S2_storerb_io:
-      V = int8_t(U);
-      break;
----------------
kparzysz wrote:
> These casts are actually necessary.  Those are store-register instructions that take a 32-bit register and store the lower 8, 16 or 32 bits, and this code tries to replace them with the equivalent store-immediate instructions.  For example, if the register contains 0x001000FF, the S2_storerb_io instruction will store 0xFF and can be replaced with a store-immediate of -1.
Oh, now I see what's going on... The truncation by int cast is a little subtle. Maybe transform `U` instead, something like:

```
switch (Opc) {
  case Hexagon::S2_storerb_io:
    U &= UINT8_MAX;
    break;
  case Hexagon::S2_storerh_io:
    U &= UINT16_MAX;
    break;
  case Hexagon::S2_storeri_io:
    U &= UINT32_MAX;
    break;
};

int64_t V = U;
if (!isInt<8>(V))
  return false;
```

?



Repository:
  rL LLVM

https://reviews.llvm.org/D50623





More information about the llvm-commits mailing list