Skip to content

Commit 2bfe2bd

Browse files
committed
SIL: Treat -1 as signed when using it to construct an "all bits set" llvm::APInt
This should enable us to revert 73c70ee.
1 parent 26540ca commit 2bfe2bd

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,10 @@ class SILBuilder {
712712
IntegerLiteralInst *createIntegerLiteral(IntegerLiteralExpr *E);
713713

714714
IntegerLiteralInst *createIntegerLiteral(SILLocation Loc, SILType Ty,
715-
intmax_t Value) {
716-
return insert(
717-
IntegerLiteralInst::create(getSILDebugLocation(Loc), Ty, Value,
718-
getModule()));
715+
intmax_t Value,
716+
bool treatAsSigned = false) {
717+
return insert(IntegerLiteralInst::create(
718+
getSILDebugLocation(Loc), Ty, Value, treatAsSigned, getModule()));
719719
}
720720
IntegerLiteralInst *createIntegerLiteral(SILLocation Loc, SILType Ty,
721721
const APInt &Value) {

include/swift/SIL/SILInstruction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4480,7 +4480,8 @@ class IntegerLiteralInst final
44804480
static IntegerLiteralInst *create(IntegerLiteralExpr *E,
44814481
SILDebugLocation Loc, SILModule &M);
44824482
static IntegerLiteralInst *create(SILDebugLocation Loc, SILType Ty,
4483-
intmax_t Value, SILModule &M);
4483+
intmax_t Value, bool treatAsSigned,
4484+
SILModule &M);
44844485
static IntegerLiteralInst *create(SILDebugLocation Loc, SILType Ty,
44854486
const APInt &Value, SILModule &M);
44864487

lib/SIL/IR/SILInstructions.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,10 +1142,11 @@ IntegerLiteralInst *IntegerLiteralInst::create(SILDebugLocation Loc,
11421142
return ::new (buf) IntegerLiteralInst(Loc, Ty, Value);
11431143
}
11441144

1145-
static APInt getAPInt(AnyBuiltinIntegerType *anyIntTy, intmax_t value) {
1145+
static APInt getAPInt(AnyBuiltinIntegerType *anyIntTy, intmax_t value,
1146+
bool treatAsSigned) {
11461147
// If we're forming a fixed-width type, build using the greatest width.
11471148
if (auto intTy = dyn_cast<BuiltinIntegerType>(anyIntTy))
1148-
return APInt(intTy->getGreatestWidth(), value);
1149+
return APInt(intTy->getGreatestWidth(), value, treatAsSigned);
11491150

11501151
// Otherwise, build using the size of the type and then truncate to the
11511152
// minimum width necessary.
@@ -1154,11 +1155,12 @@ static APInt getAPInt(AnyBuiltinIntegerType *anyIntTy, intmax_t value) {
11541155
return result;
11551156
}
11561157

1157-
IntegerLiteralInst *IntegerLiteralInst::create(SILDebugLocation Loc,
1158-
SILType Ty, intmax_t Value,
1158+
IntegerLiteralInst *IntegerLiteralInst::create(SILDebugLocation Loc, SILType Ty,
1159+
intmax_t Value,
1160+
bool treatAsSigned,
11591161
SILModule &M) {
11601162
auto intTy = Ty.castTo<AnyBuiltinIntegerType>();
1161-
return create(Loc, Ty, getAPInt(intTy, Value), M);
1163+
return create(Loc, Ty, getAPInt(intTy, Value, treatAsSigned), M);
11621164
}
11631165

11641166
static SILType getGreatestIntegerType(Type type, SILModule &M) {

lib/SILOptimizer/LoopTransforms/BoundsCheckOpts.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,8 @@ BoundsCheckOpts::findAndOptimizeInductionVariables(SILLoop *loop) {
13631363
if (isComparisonKnownTrue(builtin, *ivar)) {
13641364
if (!trueVal)
13651365
trueVal = builder.createIntegerLiteral(builtin->getLoc(),
1366-
builtin->getType(), -1);
1366+
builtin->getType(), -1,
1367+
/*treatAsSigned=*/true);
13671368
builtin->replaceAllUsesWith(trueVal);
13681369
changed = true;
13691370
continue;

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2976,7 +2976,8 @@ static SILValue testAllControlVariableBits(SILLocation Loc,
29762976
if (IVType->getFixedWidth() == 1)
29772977
return CondVal;
29782978

2979-
SILValue AllBitsSet = B.createIntegerLiteral(Loc, CondVal->getType(), -1);
2979+
SILValue AllBitsSet = B.createIntegerLiteral(Loc, CondVal->getType(), -1,
2980+
/*treatAsSigned=*/true);
29802981
if (!CmpEqFn.get())
29812982
CmpEqFn = getBinaryFunction("cmp_eq", CondVal->getType(),
29822983
B.getASTContext());

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ static SILValue createValueForEdge(SILInstruction *UserInst,
304304

305305
if (auto *CBI = dyn_cast<CondBranchInst>(DominatingTerminator))
306306
return Builder.createIntegerLiteral(
307-
CBI->getLoc(), CBI->getCondition()->getType(), EdgeIdx == 0 ? -1 : 0);
307+
CBI->getLoc(), CBI->getCondition()->getType(), EdgeIdx == 0 ? -1 : 0,
308+
/*treatAsSigned=*/true);
308309

309310
auto *SEI = cast<SwitchEnumInst>(DominatingTerminator);
310311
auto *DstBlock = SEI->getSuccessors()[EdgeIdx].getBB();
@@ -1480,7 +1481,8 @@ static SILValue invertExpectAndApplyTo(SILBuilder &Builder,
14801481
if (!IL)
14811482
return V;
14821483
SILValue NegatedExpectedValue = Builder.createIntegerLiteral(
1483-
IL->getLoc(), Args[1]->getType(), IL->getValue() == 0 ? -1 : 0);
1484+
IL->getLoc(), Args[1]->getType(), IL->getValue() == 0 ? -1 : 0,
1485+
/*treatAsSigned=*/true);
14841486
return Builder.createBuiltin(BI->getLoc(), BI->getName(), BI->getType(), {},
14851487
{V, NegatedExpectedValue});
14861488
}

0 commit comments

Comments
 (0)