diff --git a/include/swift/SIL/SILBuilder.h b/include/swift/SIL/SILBuilder.h index a7de04820d7..f9e058dff2a 100644 --- a/include/swift/SIL/SILBuilder.h +++ b/include/swift/SIL/SILBuilder.h @@ -712,10 +712,10 @@ public: IntegerLiteralInst *createIntegerLiteral(IntegerLiteralExpr *E); IntegerLiteralInst *createIntegerLiteral(SILLocation Loc, SILType Ty, - intmax_t Value) { - return insert( - IntegerLiteralInst::create(getSILDebugLocation(Loc), Ty, Value, - getModule())); + intmax_t Value, + bool treatAsSigned = false) { + return insert(IntegerLiteralInst::create( + getSILDebugLocation(Loc), Ty, Value, treatAsSigned, getModule())); } IntegerLiteralInst *createIntegerLiteral(SILLocation Loc, SILType Ty, const APInt &Value) { diff --git a/include/swift/SIL/SILInstruction.h b/include/swift/SIL/SILInstruction.h index 21a7bedc1b2..9f3bfc7bf5d 100644 --- a/include/swift/SIL/SILInstruction.h +++ b/include/swift/SIL/SILInstruction.h @@ -4480,7 +4480,8 @@ class IntegerLiteralInst final static IntegerLiteralInst *create(IntegerLiteralExpr *E, SILDebugLocation Loc, SILModule &M); static IntegerLiteralInst *create(SILDebugLocation Loc, SILType Ty, - intmax_t Value, SILModule &M); + intmax_t Value, bool treatAsSigned, + SILModule &M); static IntegerLiteralInst *create(SILDebugLocation Loc, SILType Ty, const APInt &Value, SILModule &M); diff --git a/lib/SIL/IR/SILInstructions.cpp b/lib/SIL/IR/SILInstructions.cpp index 7275813a115..6d7f6117205 100644 --- a/lib/SIL/IR/SILInstructions.cpp +++ b/lib/SIL/IR/SILInstructions.cpp @@ -1142,10 +1142,11 @@ IntegerLiteralInst *IntegerLiteralInst::create(SILDebugLocation Loc, return ::new (buf) IntegerLiteralInst(Loc, Ty, Value); } -static APInt getAPInt(AnyBuiltinIntegerType *anyIntTy, intmax_t value) { +static APInt getAPInt(AnyBuiltinIntegerType *anyIntTy, intmax_t value, + bool treatAsSigned) { // If we're forming a fixed-width type, build using the greatest width. if (auto intTy = dyn_cast(anyIntTy)) - return APInt(intTy->getGreatestWidth(), value); + return APInt(intTy->getGreatestWidth(), value, treatAsSigned); // Otherwise, build using the size of the type and then truncate to the // minimum width necessary. @@ -1154,11 +1155,12 @@ static APInt getAPInt(AnyBuiltinIntegerType *anyIntTy, intmax_t value) { return result; } -IntegerLiteralInst *IntegerLiteralInst::create(SILDebugLocation Loc, - SILType Ty, intmax_t Value, +IntegerLiteralInst *IntegerLiteralInst::create(SILDebugLocation Loc, SILType Ty, + intmax_t Value, + bool treatAsSigned, SILModule &M) { auto intTy = Ty.castTo(); - return create(Loc, Ty, getAPInt(intTy, Value), M); + return create(Loc, Ty, getAPInt(intTy, Value, treatAsSigned), M); } static SILType getGreatestIntegerType(Type type, SILModule &M) { diff --git a/lib/SILOptimizer/LoopTransforms/BoundsCheckOpts.cpp b/lib/SILOptimizer/LoopTransforms/BoundsCheckOpts.cpp index eb55e0e57d7..4e90e982a8f 100644 --- a/lib/SILOptimizer/LoopTransforms/BoundsCheckOpts.cpp +++ b/lib/SILOptimizer/LoopTransforms/BoundsCheckOpts.cpp @@ -1363,7 +1363,8 @@ BoundsCheckOpts::findAndOptimizeInductionVariables(SILLoop *loop) { if (isComparisonKnownTrue(builtin, *ivar)) { if (!trueVal) trueVal = builder.createIntegerLiteral(builtin->getLoc(), - builtin->getType(), -1); + builtin->getType(), -1, + /*treatAsSigned=*/true); builtin->replaceAllUsesWith(trueVal); changed = true; continue; diff --git a/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp b/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp index a385a2475d4..a9a161c8165 100644 --- a/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp +++ b/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp @@ -2976,7 +2976,8 @@ 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, + /*treatAsSigned=*/true); if (!CmpEqFn.get()) CmpEqFn = getBinaryFunction("cmp_eq", CondVal->getType(), B.getASTContext()); diff --git a/lib/SILOptimizer/Transforms/SimplifyCFG.cpp b/lib/SILOptimizer/Transforms/SimplifyCFG.cpp index 95a835cb07a..79f0c230481 100644 --- a/lib/SILOptimizer/Transforms/SimplifyCFG.cpp +++ b/lib/SILOptimizer/Transforms/SimplifyCFG.cpp @@ -304,7 +304,8 @@ static SILValue createValueForEdge(SILInstruction *UserInst, if (auto *CBI = dyn_cast(DominatingTerminator)) return Builder.createIntegerLiteral( - CBI->getLoc(), CBI->getCondition()->getType(), EdgeIdx == 0 ? -1 : 0); + CBI->getLoc(), CBI->getCondition()->getType(), EdgeIdx == 0 ? -1 : 0, + /*treatAsSigned=*/true); auto *SEI = cast(DominatingTerminator); auto *DstBlock = SEI->getSuccessors()[EdgeIdx].getBB(); @@ -1480,7 +1481,8 @@ 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, + /*treatAsSigned=*/true); return Builder.createBuiltin(BI->getLoc(), BI->getName(), BI->getType(), {}, {V, NegatedExpectedValue}); }