fix: apint comparisons with mixed bitwidths
@@ -36,19 +36,10 @@ struct AtomAttributeStorage : public AttributeStorage {
bool operator==(const KeyTy &key) const {
auto keyType = std::get<Type>(key);
auto keyId = std::get<APInt>(key);
- auto idBits = id.getBitWidth();
- auto keyIdBits = keyId.getBitWidth();
- if (idBits == keyIdBits) {
- return keyType == getType() && keyId == id;
- } else if (idBits < keyIdBits) {
- APInt temp(id);
- temp.zext(keyIdBits);
- return keyType == getType() && keyId == temp;
- } else {
- APInt temp(keyId);
- temp.zext(idBits);
- return keyType == getType() && id == temp;
- }
+ if (id.getLimitedValue() == keyId.getLimitedValue())
+ return keyType == getType();
+ else
+ return false;
}
static llvm::hash_code hashKey(const KeyTy &key) {
@@ -112,12 +103,10 @@ struct APIntAttributeStorage : public AttributeStorage {
if (valueBits == keyValueBits) {
return keyType == getType() && keyValue == value;
} else if (valueBits < keyValueBits) {
- APInt temp(value);
- temp.sext(keyValueBits);
+ APInt temp = value.sext(keyValueBits);
return keyType == getType() && keyValue == temp;
} else {
- APInt temp(keyValue);
- temp.sext(valueBits);
+ APInt temp = keyValue.sext(valueBits);
return keyType == getType() && value == temp;
}
}
