[llvm-dev] Matching ConstantFPSDNode tablegen

Ryan Taylor via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 7 10:45:08 PDT 2018


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180607/d9c757c7/attachment.html>


More information about the llvm-dev mailing list