[llvm-dev] Matching ConstantFPSDNode tablegen

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

[llvm-dev] Matching ConstantFPSDNode tablegen

U.Mutlu via llvm-dev
I'm trying to match a ConstantFPSDNode == 0 in dag pattern for tablegen but am having some issues.

So LLVM doesn't seem to accept a floating point constant literal match like:

%v = call <4 x float> @foo(i32 15, float %s, float 0.0, <8 x i32> %rsrc, <4 x i32> %samp, i1 0, i32 0, i32 0)
  ret <4 x float> %v

def : XXXPat<(v4f32 (int_foo i32:$mask, f32:$s, 0, v8i32:$rsrc, v4i32:$sampler, i1:$unorm, 0, i32:$cachepolicy)), (FOO_MI (COPY_TO_REGCLASS ?:$s, 32RegClass), ?:$rsrc, ?:$sampler, (as_i32imm ?:$mask), (as_i1imm ?:$unorm), (as_i1imm ?:$cachepolicy), (as_i1imm ?:$cachepolicy), 0, 0, 0, { 0 })>;

which would be ideal. This seems to be because OPC_CheckInteger only checks for ConstantSDNode and not ConstantFPSDNode. So it was suggested to use ComplexPattern, so given:

bool XXXDAGToDAGISel::SelectConstantFPSDNodeImmZero(SDValue In, SDValue &Src) const {
  if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(In))
    return C->isZero();
  return false;
}

def ConstantFPSDNodeImmZero : ComplexPattern<f32, 0, "SelectConstantFPSDNodeImmZero">;

def : XXXPat<(v4f32 (int_foo i32:$dmask, f32:$s, (f32 (ConstantFPSDNodeImmZero f32:$lod)), v8i32:$rsrc, v4i32:$sampler, i1:$unorm, 0, i32:$cachepolicy)), (FOO_MI (COPY_TO_REGCLASS ?:$s, 32RegClass), ?:$rsrc, ?:$sampler, (as_i32imm ?:$dmask), (as_i1imm ?:$unorm), (as_i1imm ?:$cachepolicy), (as_i1imm ?:$cachepolicy), 0, 0, 0, { 0 })>;


The problem here is that lod is that 'pattern has dead named input lod'. I removed the 'lod' but then I get:

error: no matching function for call to ‘{anonymous}::XXXDAGToDAGISel::SelectConstantFPSDNodeImmZero(llvm::SDValue&)’
   return SelectConstantFPSDNodeImmZero(N);

which makes sense, the Select function needs an input to check, which I believe I was calling 'lod' and sending as the input param. It seems like LLVM doesn't llke a variable used in the pattern to match that isn't then also used in the output MI, which sort of seems quite limiting honestly but I suppose this wouldn't be seen if 'lod' was an int and not a float.



_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Matching ConstantFPSDNode tablegen

U.Mutlu via llvm-dev
On 6/7/2018 10:45 AM, Ryan Taylor via llvm-dev wrote:

> I'm trying to match a ConstantFPSDNode == 0 in dag pattern for
> tablegen but am having some issues.
>
> So LLVM doesn't seem to accept a floating point constant literal match
> like:
>
> %v = call <4 x float> @foo(i32 15, float %s, float 0.0, <8 x i32>
> %rsrc, <4 x i32> %samp, i1 0, i32 0, i32 0)
>   ret <4 x float> %v
>
> def : XXXPat<(v4f32 (int_foo i32:$mask, f32:$s, 0, v8i32:$rsrc,
> v4i32:$sampler, i1:$unorm, 0, i32:$cachepolicy)), (FOO_MI
> (COPY_TO_REGCLASS ?:$s, 32RegClass), ?:$rsrc, ?:$sampler, (as_i32imm
> ?:$mask), (as_i1imm ?:$unorm), (as_i1imm ?:$cachepolicy), (as_i1imm
> ?:$cachepolicy), 0, 0, 0, { 0 })>;
>
> which would be ideal. This seems to be because OPC_CheckInteger only
> checks for ConstantSDNode and not ConstantFPSDNode. So it was
> suggested to use ComplexPattern, so given:
>
> bool XXXDAGToDAGISel::SelectConstantFPSDNodeImmZero(SDValue In,
> SDValue &Src) const {
>   if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(In))
>     return C->isZero();
>   return false;
> }
>
> def ConstantFPSDNodeImmZero : ComplexPattern<f32, 0,
> "SelectConstantFPSDNodeImmZero">;
>
> def : XXXPat<(v4f32 (int_foo i32:$dmask, f32:$s, (f32
> (ConstantFPSDNodeImmZero f32:$lod)), v8i32:$rsrc, v4i32:$sampler,
> i1:$unorm, 0, i32:$cachepolicy)), (FOO_MI (COPY_TO_REGCLASS ?:$s,
> 32RegClass), ?:$rsrc, ?:$sampler, (as_i32imm ?:$dmask), (as_i1imm
> ?:$unorm), (as_i1imm ?:$cachepolicy), (as_i1imm ?:$cachepolicy), 0, 0,
> 0, { 0 })>;

This isn't right; an floating-point immediate doesn't have any inputs.

A bunch of backends have a pattern like this; grep for fpimm0.

-Eli

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Matching ConstantFPSDNode tablegen

U.Mutlu via llvm-dev
Eli,

 Ok, thanks, this makes more sense.



On Thu, Jun 7, 2018 at 2:17 PM, Friedman, Eli <[hidden email]> wrote:
On 6/7/2018 10:45 AM, Ryan Taylor via llvm-dev wrote:
I'm trying to match a ConstantFPSDNode == 0 in dag pattern for tablegen but am having some issues.

So LLVM doesn't seem to accept a floating point constant literal match like:

%v = call <4 x float> @foo(i32 15, float %s, float 0.0, <8 x i32> %rsrc, <4 x i32> %samp, i1 0, i32 0, i32 0)
  ret <4 x float> %v

def : XXXPat<(v4f32 (int_foo i32:$mask, f32:$s, 0, v8i32:$rsrc, v4i32:$sampler, i1:$unorm, 0, i32:$cachepolicy)), (FOO_MI (COPY_TO_REGCLASS ?:$s, 32RegClass), ?:$rsrc, ?:$sampler, (as_i32imm ?:$mask), (as_i1imm ?:$unorm), (as_i1imm ?:$cachepolicy), (as_i1imm ?:$cachepolicy), 0, 0, 0, { 0 })>;

which would be ideal. This seems to be because OPC_CheckInteger only checks for ConstantSDNode and not ConstantFPSDNode. So it was suggested to use ComplexPattern, so given:

bool XXXDAGToDAGISel::SelectConstantFPSDNodeImmZero(SDValue In, SDValue &Src) const {
  if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(In))
    return C->isZero();
  return false;
}

def ConstantFPSDNodeImmZero : ComplexPattern<f32, 0, "SelectConstantFPSDNodeImmZero">;

def : XXXPat<(v4f32 (int_foo i32:$dmask, f32:$s, (f32 (ConstantFPSDNodeImmZero f32:$lod)), v8i32:$rsrc, v4i32:$sampler, i1:$unorm, 0, i32:$cachepolicy)), (FOO_MI (COPY_TO_REGCLASS ?:$s, 32RegClass), ?:$rsrc, ?:$sampler, (as_i32imm ?:$dmask), (as_i1imm ?:$unorm), (as_i1imm ?:$cachepolicy), (as_i1imm ?:$cachepolicy), 0, 0, 0, { 0 })>;

This isn't right; an floating-point immediate doesn't have any inputs.

A bunch of backends have a pattern like this; grep for fpimm0.

-Eli

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project



_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev