mirror of
https://github.com/intel/llvm.git
synced 2026-01-17 14:48:27 +08:00
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:
@@ -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))
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user