Index: llvm/include/llvm/IR/ModuleSummaryIndex.h =================================================================== --- llvm/include/llvm/IR/ModuleSummaryIndex.h +++ llvm/include/llvm/IR/ModuleSummaryIndex.h @@ -317,10 +317,10 @@ /// All-Ones Bit Vectors") } TheKind = Unsat; - /// Range of the size expressed as a bit width. For example, if the size is in - /// range [0,256), this number will be 8. This helps generate the most compact + /// Range of size-1 expressed as a bit width. For example, if the size is in + /// range [1,256], this number will be 8. This helps generate the most compact /// instruction sequences. - unsigned SizeBitWidth = 0; + unsigned SizeM1BitWidth = 0; }; struct TypeIdSummary { Index: llvm/include/llvm/IR/ModuleSummaryIndexYAML.h =================================================================== --- llvm/include/llvm/IR/ModuleSummaryIndexYAML.h +++ llvm/include/llvm/IR/ModuleSummaryIndexYAML.h @@ -29,7 +29,7 @@ template <> struct MappingTraits { static void mapping(IO &io, TypeTestResolution &res) { io.mapOptional("Kind", res.TheKind); - io.mapOptional("SizeBitWidth", res.SizeBitWidth); + io.mapOptional("SizeM1BitWidth", res.SizeM1BitWidth); } }; Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp =================================================================== --- llvm/lib/Transforms/IPO/LowerTypeTests.cpp +++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp @@ -262,12 +262,12 @@ /// relative to the start address. Constant *AlignLog2; - /// ByteArray, Inline, AllOnes: size of the memory region covering members - /// of this type identifier as a multiple of 2^AlignLog2. - Constant *Size; + /// ByteArray, Inline, AllOnes: one less than the size of the memory region + /// covering members of this type identifier as a multiple of 2^AlignLog2. + Constant *SizeM1; - /// ByteArray, Inline, AllOnes: range of the size expressed as a bit width. - unsigned SizeBitWidth; + /// ByteArray, Inline, AllOnes: range of SizeM1 expressed as a bit width. + unsigned SizeM1BitWidth; /// ByteArray: the byte array to test the address against. Constant *TheByteArray; @@ -565,8 +565,8 @@ IntPtrTy)); Value *BitOffset = B.CreateOr(OffsetSHR, OffsetSHL); - Constant *BitSizeConst = ConstantExpr::getZExt(TIL.Size, IntPtrTy); - Value *OffsetInRange = B.CreateICmpULT(BitOffset, BitSizeConst); + Constant *BitSizeConst = ConstantExpr::getZExt(TIL.SizeM1, IntPtrTy); + Value *OffsetInRange = B.CreateICmpULE(BitOffset, BitSizeConst); // If the bit set is all ones, testing against it is unnecessary. if (TIL.TheKind == TypeTestResolution::AllOnes) @@ -683,13 +683,13 @@ if (BSI.isAllOnes()) { TIL.TheKind = (BSI.BitSize == 1) ? TypeTestResolution::Single : TypeTestResolution::AllOnes; - TIL.SizeBitWidth = (BSI.BitSize <= 256) ? 8 : 32; - TIL.Size = ConstantInt::get((BSI.BitSize <= 256) ? Int8Ty : Int32Ty, - BSI.BitSize); + TIL.SizeM1BitWidth = (BSI.BitSize <= 128) ? 7 : 32; + TIL.SizeM1 = ConstantInt::get((BSI.BitSize <= 128) ? Int8Ty : Int32Ty, + BSI.BitSize - 1); } else if (BSI.BitSize <= 64) { TIL.TheKind = TypeTestResolution::Inline; - TIL.SizeBitWidth = (BSI.BitSize <= 32) ? 5 : 6; - TIL.Size = ConstantInt::get(Int8Ty, BSI.BitSize); + TIL.SizeM1BitWidth = (BSI.BitSize <= 32) ? 5 : 6; + TIL.SizeM1 = ConstantInt::get(Int8Ty, BSI.BitSize - 1); uint64_t InlineBits = 0; for (auto Bit : BSI.Bits) InlineBits |= uint64_t(1) << Bit; @@ -700,9 +700,9 @@ (BSI.BitSize <= 32) ? Int32Ty : Int64Ty, InlineBits); } else { TIL.TheKind = TypeTestResolution::ByteArray; - TIL.SizeBitWidth = (BSI.BitSize <= 256) ? 8 : 32; - TIL.Size = ConstantInt::get((BSI.BitSize <= 256) ? Int8Ty : Int32Ty, - BSI.BitSize); + TIL.SizeM1BitWidth = (BSI.BitSize <= 128) ? 7 : 32; + TIL.SizeM1 = ConstantInt::get((BSI.BitSize <= 128) ? Int8Ty : Int32Ty, + BSI.BitSize - 1); ++NumByteArraysCreated; ByteArrayInfo *BAI = createByteArray(BSI); TIL.TheByteArray = BAI->ByteArray; Index: llvm/test/Transforms/LowerTypeTests/Inputs/import-unsat.yaml =================================================================== --- llvm/test/Transforms/LowerTypeTests/Inputs/import-unsat.yaml +++ llvm/test/Transforms/LowerTypeTests/Inputs/import-unsat.yaml @@ -6,5 +6,5 @@ typeid1: TTRes: Kind: Unsat - SizeBitWidth: 0 + SizeM1BitWidth: 0 ... Index: llvm/test/Transforms/LowerTypeTests/function.ll =================================================================== --- llvm/test/Transforms/LowerTypeTests/function.ll +++ llvm/test/Transforms/LowerTypeTests/function.ll @@ -43,7 +43,7 @@ define i1 @foo(i8* %p) { ; NATIVE: sub i64 {{.*}}, ptrtoint (void ()* @[[JT]] to i64) ; WASM32: sub i64 {{.*}}, ptrtoint (i8* getelementptr (i8, i8* null, i64 1) to i64) - ; WASM32: icmp ult i64 {{.*}}, 2 + ; WASM32: icmp ule i64 {{.*}}, 1 %x = call i1 @llvm.type.test(i8* %p, metadata !"typeid1") ret i1 %x } Index: llvm/test/Transforms/LowerTypeTests/import-unsat.ll =================================================================== --- llvm/test/Transforms/LowerTypeTests/import-unsat.ll +++ llvm/test/Transforms/LowerTypeTests/import-unsat.ll @@ -10,7 +10,7 @@ ; SUMMARY-NEXT: typeid1: ; SUMMARY-NEXT: TTRes: ; SUMMARY-NEXT: Kind: Unsat -; SUMMARY-NEXT: SizeBitWidth: 0 +; SUMMARY-NEXT: SizeM1BitWidth: 0 target datalayout = "e-p:32:32" Index: llvm/test/Transforms/LowerTypeTests/simple.ll =================================================================== --- llvm/test/Transforms/LowerTypeTests/simple.ll +++ llvm/test/Transforms/LowerTypeTests/simple.ll @@ -69,7 +69,7 @@ ; CHECK: [[R3:%[^ ]*]] = lshr i32 [[R2]], 2 ; CHECK: [[R4:%[^ ]*]] = shl i32 [[R2]], 30 ; CHECK: [[R5:%[^ ]*]] = or i32 [[R3]], [[R4]] - ; CHECK: [[R6:%[^ ]*]] = icmp ult i32 [[R5]], 68 + ; CHECK: [[R6:%[^ ]*]] = icmp ule i32 [[R5]], 67 ; CHECK: br i1 [[R6]] ; CHECK: [[R8:%[^ ]*]] = getelementptr i8, i8* @bits_use.{{[0-9]*}}, i32 [[R5]] @@ -96,7 +96,7 @@ ; CHECK: [[S3:%[^ ]*]] = lshr i32 [[S2]], 8 ; CHECK: [[S4:%[^ ]*]] = shl i32 [[S2]], 24 ; CHECK: [[S5:%[^ ]*]] = or i32 [[S3]], [[S4]] - ; CHECK: [[S6:%[^ ]*]] = icmp ult i32 [[S5]], 2 + ; CHECK: [[S6:%[^ ]*]] = icmp ule i32 [[S5]], 1 %x = call i1 @llvm.type.test(i8* %pi8, metadata !"typeid2") ; CHECK: ret i1 [[S6]] @@ -112,7 +112,7 @@ ; CHECK: [[T3:%[^ ]*]] = lshr i32 [[T2]], 2 ; CHECK: [[T4:%[^ ]*]] = shl i32 [[T2]], 30 ; CHECK: [[T5:%[^ ]*]] = or i32 [[T3]], [[T4]] - ; CHECK: [[T6:%[^ ]*]] = icmp ult i32 [[T5]], 66 + ; CHECK: [[T6:%[^ ]*]] = icmp ule i32 [[T5]], 65 ; CHECK: br i1 [[T6]] ; CHECK: [[T8:%[^ ]*]] = getelementptr i8, i8* @bits_use{{(\.[0-9]*)?}}, i32 [[T5]]