Skip to content

[rebranch] SIL: Restore old behavior in llvm::APInt ctor call #81464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2025
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);

// 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});
}
}
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