Skip to content

Commit d5d96ec

Browse files
committed
Address feedback from code review
* Unnecessary AQWord extraction when we can directly extract ctrl from A. * Use setBitVal instead of insertBits(extractBits)
1 parent 33c6cb0 commit d5d96ec

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3556,27 +3556,26 @@ static bool interp__builtin_ia32_multishiftqb(InterpState &S, CodePtr OpPC,
35563556
const Pointer &Dst = S.Stk.peek<Pointer>();
35573557

35583558
for (unsigned QWordId = 0; QWordId != NumQWords; ++QWordId) {
3559-
APInt AQWord(64, 0);
35603559
APInt BQWord(64, 0);
35613560
for (unsigned ByteIdx = 0; ByteIdx != NumBytesInQWord; ++ByteIdx) {
35623561
unsigned Idx = QWordId * NumBytesInQWord + ByteIdx;
3563-
uint64_t Byte = 0;
35643562
INT_TYPE_SWITCH(ElemT, {
3565-
Byte = static_cast<uint64_t>(APtr.elem<T>(Idx));
3566-
AQWord.insertBits(APInt(8, Byte & 0xFF), ByteIdx * NumBitsInByte);
3567-
3568-
Byte = static_cast<uint64_t>(BPtr.elem<T>(Idx));
3563+
uint64_t Byte = static_cast<uint64_t>(BPtr.elem<T>(Idx));
35693564
BQWord.insertBits(APInt(8, Byte & 0xFF), ByteIdx * NumBitsInByte);
35703565
});
35713566
}
35723567

35733568
for (unsigned ByteIdx = 0; ByteIdx != NumBytesInQWord; ++ByteIdx) {
3574-
uint64_t Ctrl =
3575-
AQWord.extractBits(8, ByteIdx * NumBitsInByte).getZExtValue() & 0x3F;
3569+
uint64_t Ctrl = 0;
3570+
INT_TYPE_SWITCH(ElemT, {
3571+
Ctrl = static_cast<uint64_t>(
3572+
APtr.elem<T>(QWordId * NumBytesInQWord + ByteIdx)) &
3573+
0x3F;
3574+
});
35763575

35773576
APInt Byte(8, 0);
35783577
for (unsigned BitIdx = 0; BitIdx != NumBitsInByte; ++BitIdx) {
3579-
Byte.insertBits(BQWord.extractBits(1, (Ctrl + BitIdx) & 0x3F), BitIdx);
3578+
Byte.setBitVal(BitIdx, BQWord[(Ctrl + BitIdx) & 0x3F]);
35803579
}
35813580
INT_TYPE_SWITCH(ElemT, {
35823581
Dst.elem<T>(QWordId * NumBytesInQWord + ByteIdx) =

clang/lib/AST/ExprConstant.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13114,26 +13114,22 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1311413114
Result.reserve(NumBytes);
1311513115

1311613116
for (unsigned QWordId = 0; QWordId != NumQWords; ++QWordId) {
13117-
APInt AQWord(64, 0);
1311813117
APInt BQWord(64, 0);
1311913118
for (unsigned ByteIdx = 0; ByteIdx != NumBytesInQWord; ++ByteIdx) {
1312013119
unsigned Idx = QWordId * NumBytesInQWord + ByteIdx;
13121-
uint64_t Byte = A.getVectorElt(Idx).getInt().getZExtValue();
13122-
AQWord.insertBits(APInt(8, Byte & 0xFF), ByteIdx * NumBitsInByte);
13123-
13124-
Byte = B.getVectorElt(Idx).getInt().getZExtValue();
13120+
uint64_t Byte = B.getVectorElt(Idx).getInt().getZExtValue();
1312513121
BQWord.insertBits(APInt(8, Byte & 0xFF), ByteIdx * NumBitsInByte);
1312613122
}
1312713123

1312813124
for (unsigned ByteIdx = 0; ByteIdx != NumBytesInQWord; ++ByteIdx) {
13129-
uint64_t Ctrl =
13130-
AQWord.extractBits(8, ByteIdx * NumBitsInByte).getZExtValue() &
13131-
0x3F;
13125+
uint64_t Ctrl = A.getVectorElt(QWordId * NumBytesInQWord + ByteIdx)
13126+
.getInt()
13127+
.getZExtValue() &
13128+
0x3F;
1313213129

1313313130
APInt Byte(8, 0);
1313413131
for (unsigned BitIdx = 0; BitIdx != NumBitsInByte; ++BitIdx) {
13135-
Byte.insertBits(BQWord.extractBits(1, (Ctrl + BitIdx) & 0x3F),
13136-
BitIdx);
13132+
Byte.setBitVal(BitIdx, BQWord[(Ctrl + BitIdx) & 0x3F]);
1313713133
}
1313813134
Result.push_back(APValue(APSInt(Byte, /*isUnsigned*/ true)));
1313913135
}

0 commit comments

Comments
 (0)