Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/SIL/IR/SILInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,9 @@ IntegerLiteralInst *IntegerLiteralInst::create(SILDebugLocation Loc,
static APInt getAPInt(AnyBuiltinIntegerType *anyIntTy, intmax_t value) {
// If we're forming a fixed-width type, build using the greatest width.
if (auto intTy = dyn_cast<BuiltinIntegerType>(anyIntTy))
return APInt(intTy->getGreatestWidth(), value);
// TODO: Avoid implicit trunc?
return APInt(intTy->getGreatestWidth(), value, /*isSigned=*/false,
/*implicitTrunc=*/true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're getting implicit truncation here, I feel like that's genuinely problematic and we should get an assertion.


// Otherwise, build using the size of the type and then truncate to the
// minimum width necessary.
Expand Down
9 changes: 5 additions & 4 deletions lib/SILGen/SILGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1995,11 +1995,12 @@ void SILGenFunction::emitStmtCondition(StmtCondition Cond, JumpDest FalseDest,
emitOSVersionRangeCheck(loc, versionRange.value(), isMacCatalyst);
if (availability->isUnavailability()) {
// If this is an unavailability check, invert the result
// by emitting a call to Builtin.xor_Int1(lhs, 1).
// by emitting a call to Builtin.xor_Int1(lhs, -1).
SILType i1 = SILType::getBuiltinIntegerType(1, getASTContext());
SILValue one = B.createIntegerLiteral(loc, i1, 1);
booleanTestValue = B.createBuiltinBinaryFunction(
loc, "xor", i1, i1, {booleanTestValue, one});
SILValue minusOne = B.createIntegerLiteral(loc, i1, -1);
booleanTestValue =
B.createBuiltinBinaryFunction(loc, "xor", i1, i1,
{booleanTestValue, minusOne});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We conventionally talk about single bits as 0 and 1, not 0 and -1. So I don't like the renaming, and if we've done something to make it necessary to pass -1 instead of 1 to the constructor here, that seems bad.

}
}
break;
Expand Down
6 changes: 3 additions & 3 deletions lib/SILOptimizer/LoopTransforms/BoundsCheckOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ static SILValue getSub(SILLocation Loc, SILValue Val, unsigned SubVal,
SmallVector<SILValue, 4> Args(1, Val);
Args.push_back(B.createIntegerLiteral(Loc, Val->getType(), SubVal));
Args.push_back(B.createIntegerLiteral(
Loc, SILType::getBuiltinIntegerType(1, B.getASTContext()), 1));
Loc, SILType::getBuiltinIntegerType(1, B.getASTContext()), -1));

auto *AI = B.createBuiltinBinaryFunctionWithOverflow(
Loc, "ssub_with_overflow", Args);
Expand All @@ -570,7 +570,7 @@ static SILValue getAdd(SILLocation Loc, SILValue Val, unsigned AddVal,
SmallVector<SILValue, 4> Args(1, Val);
Args.push_back(B.createIntegerLiteral(Loc, Val->getType(), AddVal));
Args.push_back(B.createIntegerLiteral(
Loc, SILType::getBuiltinIntegerType(1, B.getASTContext()), 1));
Loc, SILType::getBuiltinIntegerType(1, B.getASTContext()), -1));

auto *AI = B.createBuiltinBinaryFunctionWithOverflow(
Loc, "sadd_with_overflow", Args);
Expand Down Expand Up @@ -1342,7 +1342,7 @@ BoundsCheckOpts::findAndOptimizeInductionVariables(SILLoop *loop) {
if (isComparisonKnownTrue(builtin, *ivar)) {
if (!trueVal)
trueVal = builder.createIntegerLiteral(builtin->getLoc(),
builtin->getType(), 1);
builtin->getType(), -1);
builtin->replaceAllUsesWith(trueVal);
changed = true;
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2976,7 +2976,7 @@ static SILValue testAllControlVariableBits(SILLocation Loc,
if (IVType->getFixedWidth() == 1)
return CondVal;

SILValue AllBitsSet = B.createIntegerLiteral(Loc, CondVal->getType(), 1);
SILValue AllBitsSet = B.createIntegerLiteral(Loc, CondVal->getType(), -1);
if (!CmpEqFn.get())
CmpEqFn = getBinaryFunction("cmp_eq", CondVal->getType(),
B.getASTContext());
Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Transforms/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ static SILValue createValueForEdge(SILInstruction *UserInst,

if (auto *CBI = dyn_cast<CondBranchInst>(DominatingTerminator))
return Builder.createIntegerLiteral(
CBI->getLoc(), CBI->getCondition()->getType(), EdgeIdx == 0 ? 1 : 0);
CBI->getLoc(), CBI->getCondition()->getType(), EdgeIdx == 0 ? -1 : 0);

auto *SEI = cast<SwitchEnumInst>(DominatingTerminator);
auto *DstBlock = SEI->getSuccessors()[EdgeIdx].getBB();
Expand Down Expand Up @@ -1480,7 +1480,7 @@ static SILValue invertExpectAndApplyTo(SILBuilder &Builder,
if (!IL)
return V;
SILValue NegatedExpectedValue = Builder.createIntegerLiteral(
IL->getLoc(), Args[1]->getType(), IL->getValue() == 0 ? 1 : 0);
IL->getLoc(), Args[1]->getType(), IL->getValue() == 0 ? -1 : 0);
return Builder.createBuiltin(BI->getLoc(), BI->getName(), BI->getType(), {},
{V, NegatedExpectedValue});
}
Expand Down