This is an archive of the discontinued LLVM Phabricator instance.

[X86] Make sure SF is updated when optimizing for `jg/jge/jl/jle`
ClosedPublic

Authored by pengfei on Jun 18 2022, 7:49 AM.

Diff Detail

Event Timeline

pengfei created this revision.Jun 18 2022, 7:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2022, 7:49 AM
pengfei requested review of this revision.Jun 18 2022, 7:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2022, 7:49 AM
craig.topper added inline comments.Jun 18 2022, 11:23 AM
llvm/test/CodeGen/X86/pr56103.ll
7

Drop dso_local and unnamed-addr

50

Can we clean up the attributes and metadata nodes?

mingmingl accepted this revision.EditedJun 18 2022, 3:55 PM

thanks for root cause and quick fix! lgtm after resolving others' comments.

As mentioned in issue 56103[1], a diff of codegen in 14.0.0 and truck proves D124118 exposes the SF usage issue, so this patch is reasonable.

Besides, D124118 could update ClearsOverflowFlag; and the OF bit usage is already properly handled [2] so no other EFLAGS usage to worry about (otherwise I'd be glad to send a similar patch to this).

[1] https://github.com/llvm/llvm-project/issues/56103#issuecomment-1159575344
[2] according to the table http://unixwiz.net/techtips/x86-jumps.html

llvm/lib/Target/X86/X86InstrInfo.cpp
4463–4469

(Just to add some reference, no action items)

According to the table [1], JL JLE, JG and JGE uses SF bit, besides JS and JNS.

JS and JNS are handled around line 4478, so this should handle all jump instructions.

[1] http://unixwiz.net/techtips/x86-jumps.html and https://en.wikibooks.org/wiki/X86_Assembly/Control_Flow#Unconditional_Jumps

llvm/test/CodeGen/X86/pr56103.ll
4

nit pick:

Do we want to use utils/update_llc_test_checks.py to generate (more) assertions automatically?

This revision is now accepted and ready to land.Jun 18 2022, 3:55 PM
pengfei updated this revision to Diff 438162.Jun 18 2022, 5:52 PM

Address review comments, thanks @craig.topper and @mingmingl!

This revision was landed with ongoing or failed builds.Jun 20 2022, 6:09 PM
This revision was automatically updated to reflect the committed changes.