Skip to content

Commit 151e23b

Browse files
committed
removing repeated elem(ElemNum).toAPSInt() calls to top of the loop
1 parent c3cdc21 commit 151e23b

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,43 +3119,30 @@ static bool interp__builtin_cmp_mask(InterpState &S, CodePtr OpPC,
31193119

31203120
for (unsigned ElemNum = 0; ElemNum < VectorLen; ++ElemNum) {
31213121
INT_TYPE_SWITCH_NO_BOOL(ElemT, {
3122-
APSInt B = RHS.elem<T>(ElemNum).toAPSInt();
3122+
const APSInt &A = LHS.elem<T>(ElemNum).toAPSInt();
3123+
const APSInt &B = RHS.elem<T>(ElemNum).toAPSInt();
31233124
bool Result = false;
31243125
switch (Opcode.getExtValue() & 0x7) {
31253126
case 0x00: // _MM_CMPINT_EQ
3126-
Result = (LHS.elem<T>(ElemNum).toAPSInt() ==
3127-
RHS.elem<T>(ElemNum).toAPSInt());
3127+
Result = (A == B);
31283128
break;
31293129
case 0x01: // _MM_CMPINT_LT
3130-
Result = IsUnsigned ? LHS.elem<T>(ElemNum).toAPSInt().ult(
3131-
RHS.elem<T>(ElemNum).toAPSInt())
3132-
: LHS.elem<T>(ElemNum).toAPSInt().slt(
3133-
RHS.elem<T>(ElemNum).toAPSInt());
3130+
Result = IsUnsigned ? A.ult(B) : A.slt(B);
31343131
break;
31353132
case 0x02: // _MM_CMPINT_LE
3136-
Result = IsUnsigned ? LHS.elem<T>(ElemNum).toAPSInt().ule(
3137-
RHS.elem<T>(ElemNum).toAPSInt())
3138-
: LHS.elem<T>(ElemNum).toAPSInt().sle(
3139-
RHS.elem<T>(ElemNum).toAPSInt());
3133+
Result = IsUnsigned ? A.ule(B) : A.sle(B);
31403134
break;
31413135
case 0x03: // _MM_CMPINT_FALSE
31423136
Result = false;
31433137
break;
31443138
case 0x04: // _MM_CMPINT_NE
3145-
Result = (LHS.elem<T>(ElemNum).toAPSInt() !=
3146-
RHS.elem<T>(ElemNum).toAPSInt());
3139+
Result = (A != B);
31473140
break;
31483141
case 0x05: // _MM_CMPINT_NLT (>=)
3149-
Result = IsUnsigned ? LHS.elem<T>(ElemNum).toAPSInt().uge(
3150-
RHS.elem<T>(ElemNum).toAPSInt())
3151-
: LHS.elem<T>(ElemNum).toAPSInt().sge(
3152-
RHS.elem<T>(ElemNum).toAPSInt());
3142+
Result = IsUnsigned ? A.uge(B) : A.sge(B);
31533143
break;
31543144
case 0x06: // _MM_CMPINT_NLE (>)
3155-
Result = IsUnsigned ? LHS.elem<T>(ElemNum).toAPSInt().ugt(
3156-
RHS.elem<T>(ElemNum).toAPSInt())
3157-
: LHS.elem<T>(ElemNum).toAPSInt().sgt(
3158-
RHS.elem<T>(ElemNum).toAPSInt());
3145+
Result = IsUnsigned ? A.ugt(B) : A.sgt(B);
31593146
break;
31603147
case 0x07: // _MM_CMPINT_TRUE
31613148
Result = true;

clang/lib/AST/ExprConstant.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15497,8 +15497,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1549715497

1549815498
APSInt RetMask(llvm::APInt(RetWidth, 0), /*isUnsigned=*/true);
1549915499
for (unsigned ElemNum = 0; ElemNum < VectorLen; ++ElemNum) {
15500-
APSInt A = LHS.getVectorElt(ElemNum).getInt();
15501-
APSInt B = RHS.getVectorElt(ElemNum).getInt();
15500+
const APSInt &A = LHS.getVectorElt(ElemNum).getInt();
15501+
const APSInt &B = RHS.getVectorElt(ElemNum).getInt();
1550215502
bool result = false;
1550315503

1550415504
switch (Opcode.getExtValue() & 0x7) {
@@ -15531,7 +15531,6 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1553115531
RetMask.setBitVal(ElemNum, Mask[ElemNum] && result);
1553215532
}
1553315533

15534-
RetMask.setIsUnsigned(true);
1553515534
return Success(APValue(RetMask), E);
1553615535
}
1553715536
}

0 commit comments

Comments
 (0)