This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Fix vector ule zero lowering
ClosedPublic

Authored by dmgreen on Oct 21 2022, 6:29 AM.

Details

Summary

The instruction icmp ule <4 x i32> %0, zeroinitializer will usually be simplified to icmp eq <4 x i32> %0, zeroinitializer. It is not guaranteed though, and the code for lowering vector compares could pick the wrong form of the instruction if this happened. I've tried to make the code more explicit about the supported conditions.

This fixes NEON being unable to select VCMPZ with HS conditions, and fixes some incorrect MVE patterns.
Fixes #58514.

Diff Detail

Event Timeline

dmgreen created this revision.Oct 21 2022, 6:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 21 2022, 6:29 AM
dmgreen requested review of this revision.Oct 21 2022, 6:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 21 2022, 6:29 AM

You might be able to handle this more generally in SelectionDAG::FoldSetCC ?

Do you mean converting ule 0 -> eq 0? I wanted the code here to be correct without needing it.

Do you mean converting ule 0 -> eq 0? I wanted the code here to be correct without needing it.

yes - its called inside getNode() so will already have been run

I would still prefer the code here to be correct. It shouldn't need to rely on canonicalization to produce the correct result (or not crash).

This revision is now accepted and ready to land.Oct 31 2022, 6:58 AM

Do you mean converting ule 0 -> eq 0? I wanted the code here to be correct without needing it.

Normalizing wouldn't be entirely unprecedented in my understanding, after all we have e.g. a number of files llvm/lib/CodeGen/SelectionDAG/Legalize*. But this here also works for me.

llvm/lib/Target/ARM/ARMISelLowering.cpp
15231–15240

Does something need to be done here?

Normalizing wouldn't be entirely unprecedented in my understanding, after all we have e.g. a number of files llvm/lib/CodeGen/SelectionDAG/Legalize*. But this here also works for me.

We shouldn't leave parts of the code broken if we can fix them. Even if it was made reliable now, we don't know how the canonicalisation can change in the future.

llvm/lib/Target/ARM/ARMISelLowering.cpp
15231–15240

Hmm. Don't think so. What kind of thing do you mean?

aaronpuchert added inline comments.Nov 2 2022, 8:57 AM
llvm/lib/Target/ARM/ARMISelLowering.cpp
15231–15240

It seems to me that we're also creating ARMISD::VCMPZ nodes here, and it doesn't seem obvious to me that we're excluding the problematic ARMCC::CondCodes. But I'm probably missing something, just wanted to make sure you're aware of this function.

dmgreen added inline comments.Nov 2 2022, 9:04 AM
llvm/lib/Target/ARM/ARMISelLowering.cpp
15231–15240

I see, yeah. This code is only for MVE, and we check isValidMVECond. I think it's OK, and we should have the test coverage for it.

This revision was landed with ongoing or failed builds.Nov 2 2022, 3:34 PM
This revision was automatically updated to reflect the committed changes.