[PATCH] D109555: [APInt] Enable APInt to support zero bit integers.

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 13 09:36:56 PDT 2021


foad added a comment.

My starting point is that a zero-width //unsigned// integer makes sense and always has the value 0, but a zero-width //signed// integer makes no sense at all (I think you could "logically" argue that it is always 0, //or// that is is always -1). With that in mind...

> You're right - I think there are two logically consistent paths we could take (and this patch isn't either of them):
>
> 1. We could take your approach.
> 2. We could abort and die on `isAllOnes()` saying it is not defined.

I'd prefer (1) and I think it's logically consistent.

> The patch is already treating zero bit integers as "zero" (no bits set means the value is zero) in the `isZero()` and `isOne()` predicates, so I think that going with #1 is defensible.  We could also define `sext(zerobit)` as filling with zeros as well.  WDYT?

I think isZero and isOne and zext should all work on zero-width integers, but sext should assert that the width is non-zero.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109555/new/

https://reviews.llvm.org/D109555



More information about the llvm-commits mailing list