Vector comparisons

Are the ICMP and FCMP instructions meant to accept vectors operands or no? Verifier excludes vectors, as does the AsmParser[1]. But the CmpInst constructor accepts vectors[2], and they are documented as allowed:

If the operands [of icmp or fcmp] are packed typed, the elements of the vector are compared in turn and the predicate must hold for all elements.

— Gordon

[1]

% llvm-as <<‘EOT’ >/dev/null
define i1 %cmpvint(<4 x i32> %x, <4 x i32> %y) {
%res = icmp eq <4 x i32> %y, %y
ret %res
}
EOT
llvm-as: :2,0: Packed types not supported by icmp instruction
% llvm-as <<‘EOT’ >/dev/null
define i1 %cmpfint(<4 x float> %x, <4 x float> %y) {
%res = fcmp oeq <4 x float> %y, %y
ret %res
}
EOT
llvm-as: :2,0: Packed types not supported by fcmp instruction

[2] From CmpInst::CmpInst:

// Check that the operands are the right type
assert(Op0Ty->isInteger() || isa(Op0Ty) ||
(isa(Op0Ty) &&
cast(Op0Ty)->getElementType()->isInteger()) &&
“Invalid operand types for ICmp instruction”);

// Check that the operands are the right type
assert(Op0Ty->isFloatingPoint() || (isa(Op0Ty) &&
cast(Op0Ty)->getElementType()->isFloatingPoint()) &&
“Invalid operand types for FCmp instruction”);

Hi Gordon,

Are the ICMP and FCMP instructions meant to accept vectors operands or
no?

No.

Verifier excludes vectors, as does the AsmParser[1].

Correct.

But the CmpInst constructor accepts vectors[2],

At one time we tried to get them working, guess that's a left over.

and they are documented as allowed:

> If the operands [of icmp or fcmp] are packed typed, the elements of
> the vector are compared in turn and the predicate must hold for all
> elements.

I'll fix the documentation.

Originally we had plans for supporting vector comparisons of at least EQ
and NE predicates. The others don't really make sense. However, none of
the backends can handle it at this time. So, we made the verifier and
AsmParser exclude them. Perhaps someday this will get supported and
turned on. Open a PR if you need this.

Reid.

Are the ICMP and FCMP instructions meant to accept vectors operands or no?

At one time we tried to get them working, guess that's a left over.

I'll fix the documentation.

Don't worry about it; I'm preparing a patch which also cleans up the assertions.

Originally we had plans for supporting vector comparisons of at least EQ and NE predicates. The others don't really make sense.

That's what I thought. Anyhow, it's better that it's disallowed for now, since it leaves the door open to introducing more useful element-wise compares in the vein of x86 CMPPD or PowerPC vcmpXXfp.

Thanks, Reid.

— Gordon