[llvm-dev] Potential bug in SelectionDAGLegalize::ConvertNodeToLibcall()?

Justin Hibbits via llvm-dev llvm-dev at lists.llvm.org
Thu Jan 3 07:48:44 PST 2019


On Wed, 2 Jan 2019 16:44:56 +0000
Alex Bradbury <asb at lowrisc.org> wrote:

> On Wed, 2 Jan 2019 at 16:41, Alex Bradbury <asb at lowrisc.org> wrote:
> >
> > On Wed, 2 Jan 2019 at 15:54, Justin Hibbits via llvm-dev
> > <llvm-dev at lists.llvm.org> wrote:  
> > >
> > > Hi,
> > >
> > > I have a custom lowering operation on ISD::BITCAST for the
> > > PowerPC/SPE target, to convert 'f64 bitcast (i64 build_pair i32,
> > > i32)' into a 'f64 BUILD_SPE64 i32, i32' node, which can be seen at
> > > https://reviews.llvm.org/D54583. However, when building
> > > compiler-rt's lib/builtins/divdc3.c an assertion is triggered
> > > that BUILD_PAIR is not legal on line 24.  There should be no
> > > bitcast(buildpair) anywhere in the generation, as it should all
> > > be lowered.  However, this is not the case when lowering to a
> > > libcall it seems.  The relevant debug output, is here:
> > >
> > > Creating new node: t118: i64 = build_pair
> > > t117,t116, /home/chmeee/freebsd/contrib/compiler-rt/lib/builtins/divdc3.c:24:22
> > > Creating new node: t119: f64 = bitcast
> > > t118, /home/chmeee/freebsd/contrib/compiler-rt/lib/builtins/divdc3.c:24:22
> > > Created libcall: t119: f64 = bitcast
> > > t118, /home/chmeee/freebsd/contrib/compiler-rt/lib/builtins/divdc3.c:24:22
> > > Successfully converted node to libcall ... replacing: t38: f64 =
> > > fmaxnum t36,
> > > t37, /home/chmeee/freebsd/contrib/compiler-rt/lib/builtins/divdc3.c:24:22
> > > with:      t119: f64 = bitcast
> > > t118, /home/chmeee/freebsd/contrib/compiler-rt/lib/builtins/divdc3.c:24:22
> > >
> > > Is this a real bug, or am I missing something in my patch?  After
> > > spending quite a while on it I'm at a loss.  
> >
> > Hi Justin,
> >
> > I don't think this is a bug in ConvertNodeToLibCall - rather, it's
> > just a case where you can be tripped up by the very late lowering of
> > intrinsics calls.  
> 
> Sorry, I was imprecise. This isn't a general problem with lowering to
> intrinsics / libcalls, just where a SelectionDAG node is expanded to a
> libcall.
> 
> Best,
> 
> Alex

Hi Alex,

Thanks for your replies.  I spent a little more time hacking away at
this, and came with the following:

If 
1) we allow custom actions on the legalizing node in LegalizeOp() and
2) I add a custom action for BITCAST on f64

Everything works swimmingly.  I'm not sure if the custom action on
BITCAST f64 is correct, though, since it's not needed anywhere else.
Everywhere else it works fine with a BITCAST i64, so maybe I'm not
thinking of the problem correctly.

- Justin


More information about the llvm-dev mailing list