Skip to content

Commit

Permalink
[X86-64] Add suport to raise PCMPGTrr instruction.
Browse files Browse the repository at this point in the history
- Adresses failure exposed by issue #182.
- Add suport to raise PCMPGTrm instruction.
- Add tests to verify raising of newly added suport.
  • Loading branch information
bharadwajy committed Oct 3, 2022
1 parent 4c9293f commit ba33acc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
2 changes: 2 additions & 0 deletions X86/X86AdditionalInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,8 @@ static constexpr const_addl_instr_info::value_type MapData[] = {
{X86::PCMPEQQrr, {0, SSE_COMPARE_RR}},
{X86::PCMPEQWrm, {16, SSE_COMPARE_RM}},
{X86::PCMPEQWrr, {0, SSE_COMPARE_RR}},
{X86::PCMPGTDrr, {0, SSE_COMPARE_RR}},
{X86::PCMPGTDrm, {0, SSE_COMPARE_RM}},
{X86::PDEP32rm, {4, Unknown}},
{X86::PDEP32rr, {0, Unknown}},
{X86::PDEP64rm, {8, Unknown}},
Expand Down
18 changes: 15 additions & 3 deletions X86/X86MachineInstructionRaiserSSE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ bool X86MachineInstructionRaiser::raiseSSECompareMachineInstr(
case X86::PCMPEQDrm:
case X86::PCMPEQDrr:
case X86::PCMPEQQrm:
case X86::PCMPEQQrr: {
case X86::PCMPEQQrr:
case X86::PCMPGTDrr:
case X86::PCMPGTDrm: {
// Compare a comparison of packed bytes/words/dwords/qwords
// If a pair is equal, set the bits corresponding to 1, otherwise to 0
LLVMContext &Ctx(MF.getFunction().getContext());
Expand All @@ -290,22 +292,32 @@ bool X86MachineInstructionRaiser::raiseSSECompareMachineInstr(
"Expected operand types to be vector types of size 128");

unsigned int ElementSizeInBits;
CmpInst::Predicate CmpPred = CmpInst::BAD_ICMP_PREDICATE;
switch (MI.getOpcode()) {
case X86::PCMPEQBrm:
case X86::PCMPEQBrr:
ElementSizeInBits = 8;
CmpPred = CmpInst::ICMP_EQ;
break;
case X86::PCMPEQWrm:
case X86::PCMPEQWrr:
ElementSizeInBits = 16;
CmpPred = CmpInst::ICMP_EQ;
break;
case X86::PCMPEQDrm:
case X86::PCMPEQDrr:
ElementSizeInBits = 32;
CmpPred = CmpInst::ICMP_EQ;
break;
case X86::PCMPEQQrm:
case X86::PCMPEQQrr:
ElementSizeInBits = 64;
CmpPred = CmpInst::ICMP_EQ;
break;
case X86::PCMPGTDrr:
case X86::PCMPGTDrm:
ElementSizeInBits = 32;
CmpPred = CmpInst::ICMP_SGT;
break;
default:
llvm_unreachable("Unhandled pcmp instruction");
Expand All @@ -329,8 +341,8 @@ bool X86MachineInstructionRaiser::raiseSSECompareMachineInstr(
ExtractElementInst::Create(CmpOpVal1, Index, "", RaisedBB);
auto *CmpSegment2 =
ExtractElementInst::Create(CmpOpVal2, Index, "", RaisedBB);
auto *CmpInst = new ICmpInst(*RaisedBB, CmpInst::ICMP_EQ, CmpSegment1,
CmpSegment2, "cmp_segment");
auto *CmpInst = new ICmpInst(*RaisedBB, CmpPred, CmpSegment1, CmpSegment2,
"cmp_segment");
auto *SelectInstr =
SelectInst::Create(CmpInst, BitmaskVal, ZeroVal, "segment", RaisedBB);
Result =
Expand Down
21 changes: 21 additions & 0 deletions test/asm_test/X86/raise-pcmp.s
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
// CHECK-NEXT: 0x0000ffffffffffffffffffffffffffff
// CHECK-NEXT: 0x00000000ffffffffffffffffffffffff
// CHECK-NEXT: 0x0000000000000000ffffffffffffffff
// CHECK-NEXT: 0xffffffff000000000000000000000000
// CHECK-NEXT: 0x00ffffffffffffffffffffffffffffff
// CHECK-NEXT: 0x0000ffffffffffffffffffffffffffff
// CHECK-NEXT: 0x00000000ffffffffffffffffffffffff
// CHECK-NEXT: 0x0000000000000000ffffffffffffffff
// CHECK-NEXT: 0xffffffff000000000000000000000000
// CHECK-EMPTY

.text
Expand Down Expand Up @@ -64,6 +66,16 @@ main: # @main
mov al, 0
call printf

movdqa xmm0, [.L.val]
movdqa xmm1, [.L.val.1]
pcmpgtd xmm0, xmm1
movdqu [rsp], xmm0
mov rsi, QWORD PTR [rsp + 8]
mov rdx, QWORD PTR [rsp]
mov rdi, offset .L.str
mov al, 0
call printf

# rm
movdqa xmm0, [.L.val]
pcmpeqb xmm0, [.L.val.1]
Expand Down Expand Up @@ -101,6 +113,15 @@ main: # @main
mov al, 0
call printf

movdqa xmm0, [.L.val]
pcmpgtd xmm0, [.L.val.1]
movdqu [rsp], xmm0
mov rsi, QWORD PTR [rsp + 8]
mov rdx, QWORD PTR [rsp]
mov rdi, offset .L.str
mov al, 0
call printf

add rsp, 16
add rsp, 8
xor rax, rax
Expand Down

0 comments on commit ba33acc

Please sign in to comment.