Vector comparisons

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Vector comparisons

Gordon Henriksen-3
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: <stdin>: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: <stdin>: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<PointerType>(Op0Ty) ||
           (isa<PackedType>(Op0Ty) && 
            cast<PackedType>(Op0Ty)->getElementType()->isInteger()) &&
           "Invalid operand types for ICmp instruction");
...
  // Check that the operands are the right type
  assert(Op0Ty->isFloatingPoint() || (isa<PackedType>(Op0Ty) &&
         cast<PackedType>(Op0Ty)->getElementType()->isFloatingPoint()) &&
         "Invalid operand types for FCmp instruction");


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Vector comparisons

Reid Spencer-2
Hi Gordon,

On Fri, 2007-01-19 at 09:35 -0500, Gordon Henriksen wrote:
> 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.

>
> — 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: <stdin>: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: <stdin>: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<PointerType>(Op0Ty) ||
>            (isa<PackedType>(Op0Ty) &&
>             cast<PackedType>(Op0Ty)->getElementType()->isInteger()) &&
>            "Invalid operand types for ICmp instruction");
> ...
>   // Check that the operands are the right type
>   assert(Op0Ty->isFloatingPoint() || (isa<PackedType>(Op0Ty) &&
>          cast<PackedType>(Op0Ty)->getElementType()->isFloatingPoint())
> &&
>          "Invalid operand types for FCmp instruction");
>
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Vector comparisons

Gordon Henriksen-3
On 2007-01-19, at 11:04, Reid Spencer wrote:

> On Fri, 2007-01-19 at 09:35 -0500, Gordon Henriksen wrote:
>
>> 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


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev