Skip to content

Commit 26540ca

Browse files
committed
SIL: Do not use -1 to construct a 1-bit llvm::APInt
A -1 truncated to 1 bit is just 1, so stop overcomplicating things here.
1 parent 687e09d commit 26540ca

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/SILGen/SILGenAvailability.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ static SILValue emitAvailabilityCheck(SILGenFunction &SGF, SILLocation loc,
6767
SILValue result =
6868
B.createApply(loc, availabilityGTEFn, SubstitutionMap(), silArgs);
6969

70-
// If this is an unavailability check, invert the result using xor with -1.
70+
// If this is an unavailability check, invert the result using 1-bit xor
71+
// with 1.
7172
if (query.isUnavailability()) {
7273
SILType i1 = SILType::getBuiltinIntegerType(1, ctx);
73-
SILValue minusOne = B.createIntegerLiteral(loc, i1, -1);
74-
result =
75-
B.createBuiltinBinaryFunction(loc, "xor", i1, i1, {result, minusOne});
74+
SILValue one = B.createIntegerLiteral(loc, i1, 1);
75+
result = B.createBuiltinBinaryFunction(loc, "xor", i1, i1, {result, one});
7676
}
7777

7878
return result;

lib/SILOptimizer/LoopTransforms/BoundsCheckOpts.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static SILValue getSub(SILLocation Loc, SILValue Val, unsigned SubVal,
573573
SmallVector<SILValue, 4> Args(1, Val);
574574
Args.push_back(B.createIntegerLiteral(Loc, Val->getType(), SubVal));
575575
Args.push_back(B.createIntegerLiteral(
576-
Loc, SILType::getBuiltinIntegerType(1, B.getASTContext()), -1));
576+
Loc, SILType::getBuiltinIntegerType(1, B.getASTContext()), 1));
577577

578578
auto *AI = B.createBuiltinBinaryFunctionWithOverflow(
579579
Loc, "ssub_with_overflow", Args);
@@ -585,7 +585,7 @@ static SILValue getAdd(SILLocation Loc, SILValue Val, unsigned AddVal,
585585
SmallVector<SILValue, 4> Args(1, Val);
586586
Args.push_back(B.createIntegerLiteral(Loc, Val->getType(), AddVal));
587587
Args.push_back(B.createIntegerLiteral(
588-
Loc, SILType::getBuiltinIntegerType(1, B.getASTContext()), -1));
588+
Loc, SILType::getBuiltinIntegerType(1, B.getASTContext()), 1));
589589

590590
auto *AI = B.createBuiltinBinaryFunctionWithOverflow(
591591
Loc, "sadd_with_overflow", Args);

0 commit comments

Comments
 (0)