Skip to content

Commit a4be46e

Browse files
authored
[Clang][ByteCode][NFC] Misc minor performance fixes (#145988)
Static analysis flagged multiple places we could move instead of copy. In one case I realized we could avoid computing the same thing multiple times and did that fix instead.
1 parent 32ef4ce commit a4be46e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,8 @@ static bool interp__builtin_isfpclass(InterpState &S, CodePtr OpPC,
555555
APSInt FPClassArg = popToAPSInt(S.Stk, FPClassArgT);
556556
const Floating &F = S.Stk.pop<Floating>();
557557

558-
int32_t Result =
559-
static_cast<int32_t>((F.classify() & FPClassArg).getZExtValue());
558+
int32_t Result = static_cast<int32_t>(
559+
(F.classify() & std::move(FPClassArg)).getZExtValue());
560560
pushInteger(S, Result, Call->getType());
561561

562562
return true;
@@ -856,7 +856,7 @@ static bool interp__builtin_overflowop(InterpState &S, CodePtr OpPC,
856856

857857
if (!APSInt::isSameValue(Temp, Result))
858858
Overflow = true;
859-
Result = Temp;
859+
Result = std::move(Temp);
860860
}
861861

862862
// Write Result to ResultPtr and put Overflow on the stack.
@@ -1135,17 +1135,17 @@ static bool interp__builtin_is_aligned_up_down(InterpState &S, CodePtr OpPC,
11351135

11361136
if (isIntegralType(FirstArgT)) {
11371137
const APSInt &Src = popToAPSInt(S.Stk, FirstArgT);
1138-
APSInt Align = Alignment.extOrTrunc(Src.getBitWidth());
1138+
APInt AlignMinusOne = Alignment.extOrTrunc(Src.getBitWidth()) - 1;
11391139
if (BuiltinOp == Builtin::BI__builtin_align_up) {
11401140
APSInt AlignedVal =
1141-
APSInt((Src + (Align - 1)) & ~(Align - 1), Src.isUnsigned());
1141+
APSInt((Src + AlignMinusOne) & ~AlignMinusOne, Src.isUnsigned());
11421142
pushInteger(S, AlignedVal, Call->getType());
11431143
} else if (BuiltinOp == Builtin::BI__builtin_align_down) {
1144-
APSInt AlignedVal = APSInt(Src & ~(Align - 1), Src.isUnsigned());
1144+
APSInt AlignedVal = APSInt(Src & ~AlignMinusOne, Src.isUnsigned());
11451145
pushInteger(S, AlignedVal, Call->getType());
11461146
} else {
11471147
assert(*S.Ctx.classify(Call->getType()) == PT_Bool);
1148-
S.Stk.push<Boolean>((Src & (Align - 1)) == 0);
1148+
S.Stk.push<Boolean>((Src & AlignMinusOne) == 0);
11491149
}
11501150
return true;
11511151
}
@@ -1425,7 +1425,7 @@ static bool interp__builtin_ia32_addcarry_subborrow(InterpState &S,
14251425

14261426
QualType CarryOutType = Call->getArg(3)->getType()->getPointeeType();
14271427
PrimType CarryOutT = *S.getContext().classify(CarryOutType);
1428-
assignInteger(S, CarryOutPtr, CarryOutT, APSInt(Result, true));
1428+
assignInteger(S, CarryOutPtr, CarryOutT, APSInt(std::move(Result), true));
14291429

14301430
pushInteger(S, CarryOut, Call->getType());
14311431

0 commit comments

Comments
 (0)