Skip to content

Commit 3e99010

Browse files
Merge pull request #81464 from AnthonyLatsis/rebranch
[rebranch] SIL: Restore old behavior in `llvm::APInt` ctor call
2 parents ca4d73f + 73c70ee commit 3e99010

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

lib/SIL/IR/SILInstructions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,9 @@ IntegerLiteralInst *IntegerLiteralInst::create(SILDebugLocation Loc,
11451145
static APInt getAPInt(AnyBuiltinIntegerType *anyIntTy, intmax_t value) {
11461146
// If we're forming a fixed-width type, build using the greatest width.
11471147
if (auto intTy = dyn_cast<BuiltinIntegerType>(anyIntTy))
1148-
return APInt(intTy->getGreatestWidth(), value);
1148+
// TODO: Avoid implicit trunc?
1149+
return APInt(intTy->getGreatestWidth(), value, /*isSigned=*/false,
1150+
/*implicitTrunc=*/true);
11491151

11501152
// Otherwise, build using the size of the type and then truncate to the
11511153
// minimum width necessary.

lib/SILGen/SILGenDecl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,11 +1995,12 @@ void SILGenFunction::emitStmtCondition(StmtCondition Cond, JumpDest FalseDest,
19951995
emitOSVersionRangeCheck(loc, versionRange.value(), isMacCatalyst);
19961996
if (availability->isUnavailability()) {
19971997
// If this is an unavailability check, invert the result
1998-
// by emitting a call to Builtin.xor_Int1(lhs, 1).
1998+
// by emitting a call to Builtin.xor_Int1(lhs, -1).
19991999
SILType i1 = SILType::getBuiltinIntegerType(1, getASTContext());
2000-
SILValue one = B.createIntegerLiteral(loc, i1, 1);
2001-
booleanTestValue = B.createBuiltinBinaryFunction(
2002-
loc, "xor", i1, i1, {booleanTestValue, one});
2000+
SILValue minusOne = B.createIntegerLiteral(loc, i1, -1);
2001+
booleanTestValue =
2002+
B.createBuiltinBinaryFunction(loc, "xor", i1, i1,
2003+
{booleanTestValue, minusOne});
20032004
}
20042005
}
20052006
break;

lib/SILOptimizer/LoopTransforms/BoundsCheckOpts.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ static SILValue getSub(SILLocation Loc, SILValue Val, unsigned SubVal,
558558
SmallVector<SILValue, 4> Args(1, Val);
559559
Args.push_back(B.createIntegerLiteral(Loc, Val->getType(), SubVal));
560560
Args.push_back(B.createIntegerLiteral(
561-
Loc, SILType::getBuiltinIntegerType(1, B.getASTContext()), 1));
561+
Loc, SILType::getBuiltinIntegerType(1, B.getASTContext()), -1));
562562

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

575575
auto *AI = B.createBuiltinBinaryFunctionWithOverflow(
576576
Loc, "sadd_with_overflow", Args);
@@ -1342,7 +1342,7 @@ BoundsCheckOpts::findAndOptimizeInductionVariables(SILLoop *loop) {
13421342
if (isComparisonKnownTrue(builtin, *ivar)) {
13431343
if (!trueVal)
13441344
trueVal = builder.createIntegerLiteral(builtin->getLoc(),
1345-
builtin->getType(), 1);
1345+
builtin->getType(), -1);
13461346
builtin->replaceAllUsesWith(trueVal);
13471347
changed = true;
13481348
continue;

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2976,7 +2976,7 @@ 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);
29802980
if (!CmpEqFn.get())
29812981
CmpEqFn = getBinaryFunction("cmp_eq", CondVal->getType(),
29822982
B.getASTContext());

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ 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);
308308

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

0 commit comments

Comments
 (0)