Page MenuHomePhabricator

[SelectionDAG][Mips][Sparc] Don't allow SimplifyDemandedBits to constant fold TargetConstant nodes to a Constant.
ClosedPublic

Authored by craig.topper on Sep 20 2019, 12:26 AM.

Details

Summary

After the switch in SimplifyDemandedBits, it tries to create a
constant when possible. If the original node is a TargetConstant
the default in the switch will call computeKnownBits on the
TargetConstant which will succeed. This results in the
TargetConstant becoming a Constant. But TargetConstant exists to
avoid being changed.

I've fixed the two cases that relied on this in tree by explicitly
making the nodes constant instead of target constant. The Sparc
case is an old bug. The Mips case was recently introduced now that
ImmArg on intrinsics gets turned into a TargetConstant when the
SelectionDAG is created.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Sep 20 2019, 12:26 AM

Sparc change looks good.
Don't know about the MIPS one -- seems like probably something upstream should be creating a Constant instead of a TargetConstant, rather than converting it there?

arsenm added inline comments.Sep 20 2019, 8:24 AM
llvm/lib/Target/Mips/MipsSEISelLowering.cpp
2302–2303 ↗(On Diff #220958)

This one looks like it's using immarg for an intrinsic argument where it really shouldn't be immarg

arsenm added inline comments.Sep 20 2019, 8:28 AM
llvm/lib/Target/Mips/MipsSEISelLowering.cpp
2302–2303 ↗(On Diff #220958)

I fixed another such case in r356085; this looks like another intrinsic that ends up lowered to generic DAG opcodes so it doesn't really have the restriction

2302–2303 ↗(On Diff #220958)

r366328 rather

craig.topper marked an inline comment as done.Sep 20 2019, 8:55 AM
craig.topper added inline comments.
llvm/lib/Target/Mips/MipsSEISelLowering.cpp
2302–2303 ↗(On Diff #220958)

Should we remove the I from the builtin declaration in the frontend too?

Remove ImmArg from Mips intrinsics

arsenm added inline comments.Sep 20 2019, 9:23 AM
llvm/lib/Target/Mips/MipsSEISelLowering.cpp
2302–2303 ↗(On Diff #220958)

I would probably just remove the intrinsic and emit the plain IR for compatibility. I don't see the point of having intrinsics that lower to generic operations

arsenm accepted this revision.Sep 20 2019, 9:23 AM

LGTM but could use tests

This revision is now accepted and ready to land.Sep 20 2019, 9:23 AM

LGTM but could use tests

How would you test this? The issues fixed fail existing tests with the llvm_unreachable added to SimplifyDemandedBits.

LGTM but could use tests

How would you test this? The issues fixed fail existing tests with the llvm_unreachable added to SimplifyDemandedBits.

oh, ok

This revision was automatically updated to reflect the committed changes.

This breaks this test:

[0/2] ACTION //llvm/test:check-llvm(//llvm/utils/gn/build/toolchain:unix)
-- Testing: 33653 tests, 64 threads --
Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90
FAIL: LLVM :: Verifier/Mips/intrinsic-immarg.ll (31185 of 33653)
******************** TEST 'LLVM :: Verifier/Mips/intrinsic-immarg.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   not /usr/local/google/home/thakis/src/llvm-project/out/gn/bin/llvm-as /usr/local/google/home/thakis/src/llvm-project/llvm/test/Verifier/Mips/intrinsic-immarg.ll -o /dev/null 2>&1 | /usr/local/google/home/thakis/src/llvm-project/out/gn/bin/FileCheck /usr/local/google/home/thakis/src/llvm-project/llvm/test/Verifier/Mips/intrinsic-immarg.ll
--
Exit Code: 2

Command Output (stderr):
--
FileCheck error: '-' is empty.
FileCheck command line:  /usr/local/google/home/thakis/src/llvm-project/out/gn/bin/FileCheck /usr/local/google/home/thakis/src/llvm-project/llvm/test/Verifier/Mips/intrinsic-immarg.ll