Allow single-bit integer types to have signs. A signed one bit integer is either 0 or -1.

Reviewers: rriddle!

Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, grosul1, frgossen, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77832
This commit is contained in:
Chris Lattner
2020-04-09 14:58:28 -07:00
parent 0d525ce068
commit ab64fd39d2
4 changed files with 12 additions and 16 deletions

View File

@@ -1291,11 +1291,12 @@ void ModulePrinter::printAttribute(Attribute attr,
break;
case StandardAttributes::Integer: {
auto intAttr = attr.cast<IntegerAttr>();
// Print all signed/signless integer attributes as signed unless i1.
bool isSigned =
attrType.isIndex() || (!attrType.isUnsignedInteger() &&
attrType.getIntOrFloatBitWidth() != 1);
intAttr.getValue().print(os, isSigned);
// Only print attributes as unsigned if they are explicitly unsigned or are
// signless 1-bit values. Indexes, signed values, and multi-bit signless
// values print as signed.
bool isUnsigned =
attrType.isUnsignedInteger() || attrType.isSignlessInteger(1);
intAttr.getValue().print(os, !isUnsigned);
// IntegerAttr elides the type if I64.
if (typeElision == AttrTypeElision::May && attrType.isSignlessInteger(64))

View File

@@ -103,8 +103,6 @@ IntegerType::verifyConstructionInvariants(Location loc, unsigned width,
return emitError(loc) << "integer bitwidth is limited to "
<< IntegerType::kMaxWidth << " bits";
}
if (width == 1 && signedness != IntegerType::Signless)
return emitOptionalError(loc, "cannot have signedness semantics for i1");
return success();
}

View File

@@ -79,7 +79,12 @@ func @int_attrs_pass() {
// CHECK-SAME: attr_18 = 9223372036854775807 : si64
attr_18 = 9223372036854775807 : si64,
// CHECK-SAME: attr_19 = 18446744073709551615 : ui64
attr_19 = 18446744073709551615 : ui64
attr_19 = 18446744073709551615 : ui64,
// CHECK-SAME: attr_20 = 1 : ui1
attr_20 = 1: ui1,
// CHECK-SAME: attr_21 = -1 : si1
attr_21 = -1: si1
} : () -> ()
return

View File

@@ -200,14 +200,6 @@ func @illegaltype(i0) // expected-error {{invalid integer width}}
// -----
func @illegaltype(ui1) // expected-error {{cannot have signedness semantics for i1}}
// -----
func @illegaltype(si1) // expected-error {{cannot have signedness semantics for i1}}
// -----
func @malformed_for_percent() {
affine.for i = 1 to 10 { // expected-error {{expected SSA operand}}