Steve Montgomery
2012-Sep-26 11:21 UTC
[LLVMdev] Folding nodes with more than one use during ISel
I'm working on a backend for the Freescale CPU12 family as a hobby project
and I'm having difficulty getting the instruction selection pass to handle
the indirect indexed addressing modes. I'd really appreciate advice on how
best to handle them.
The following llvm instructions:
%arrayidx = getelementptr inbounds i8** %p, i16 3
%0 = load i8** %arrayidx, align 2, !tbaa !0
%1 = load i8* %0, align 1, !tbaa !1
%neg = xor i8 %1, -1
store i8 %neg, i8* %0, align 1, !tbaa !1
can be realised with the single CPU12 instruction which uses the indirect
indexed addressing mode:
com [6,y]
I've defined a multiclass for this type of instruction in my InstrInfo.td
and the relevant entry for this addressing mode is:
def IdxI16 : IdxPB2Inst<opcode, AddrModeIdxI16, (outs), (ins memsrc:$mem),
!strconcat (str, "\t[$mem]\t; IdxI16"),
[(store (OpNode (loadi8 (loadi16 addrIAny:$mem))),
(loadi16 addrIAny:$mem))>;
where loadi8 and loadi16 are PatFrags that match an i8 and i16 load respectively
and OpNode is, in this case, the "not" PatFrag. Pointers are 16-bit by
the way.
During instruction selection, this pattern fails to match and it seems to me
that it's because the store uses %0 directly as an operand but also uses it
by virtue of %neg (as well as via a chain). However, since all the nodes between
the store via %neg down to %0 are going to be folded into the instruction, it
feels like the test implemented in IsLegalToFold is too restrictive in this
case.
My questions are:
- has IsLegalToFold been designed this way intentionally because there is a
problem with folding in the way I want, or is it that no other targets need this
behaviour so it's not been implemented yet?
- assuming it's the latter, are there any obvious pitfalls I should watch
out for if I modify it
- if I do modify it successfully, would the change be helpful for anyone else
- is there a better way of doing what it want that doesn't involve modifying
SelectionDagISel.cpp
I'm probably going to drop into the Cambridge social this evening so if
there are any experts on this subject likely to be there, I'd be grateful
for a chat.
