Page MenuHomePhabricator

[DAG] select Cond, -1, C --> or (sext Cond), C if Cond is MVT::i1
Needs ReviewPublic

Authored by deadalnix on Fri, Aug 5, 7:32 AM.

Details

Summary

This seems to be beneficial overall, except for midpoint-int.ll .

The X86 backend seems to generate zeroing that are not necesary.

Diff Detail

Unit TestsFailed

TimeTest
140 msx64 debian > LLVM.CodeGen/PowerPC::bool-math.ll
Script: -- : 'RUN: at line 2'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/llc < /var/lib/buildkite-agent/builds/llvm-project/llvm/test/CodeGen/PowerPC/bool-math.ll -mtriple=powerpc64le-- -verify-machineinstrs | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/llvm/test/CodeGen/PowerPC/bool-math.ll

Event Timeline

deadalnix created this revision.Fri, Aug 5, 7:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptFri, Aug 5, 7:32 AM
deadalnix requested review of this revision.Fri, Aug 5, 7:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptFri, Aug 5, 7:32 AM
deadalnix added inline comments.Fri, Aug 5, 7:39 AM
llvm/test/CodeGen/X86/memcmp-more-load-pairs-x32.ll
163–166

This seems to be unnecessary.

pengfei added inline comments.Fri, Aug 5, 8:02 AM
llvm/test/CodeGen/X86/memcmp-more-load-pairs-x32.ll
163–166
deadalnix added inline comments.Fri, Aug 5, 8:48 AM
llvm/test/CodeGen/X86/memcmp-more-load-pairs-x32.ll
163–166

Good catch, thanks.

deadalnix updated this revision to Diff 450454.Fri, Aug 5, 5:52 PM

Reabse and variosu tweaks.

deadalnix retitled this revision from [DAG] select Cond, C, -1 --> or (sext Cond), C if Cond is MVT::i1 to [DAG] select Cond, -1, C --> or (sext Cond), C if Cond is MVT::i1.Fri, Aug 5, 6:51 PM
deadalnix added inline comments.Sat, Aug 6, 6:52 PM
llvm/test/CodeGen/X86/select_const.ll
290

TODO: (sext Cond) | (Pow2 - 1) -> Pow2 - (zext (not Cond)) ?

Maybe if inverting Cond if for free? Is there a way to check for this?

Or maybe this is best reserved for X86DAGToDAGISel::matchAddressRecursively?

deadalnix added inline comments.Sat, Aug 6, 7:05 PM
llvm/test/CodeGen/X86/select_const.ll
290

I meant (sext Cond) | (Pow2 - 1) -> (zext (not Cond)) * Pow2 - 1 ?

deadalnix added inline comments.Sun, Aug 7, 7:37 AM
llvm/test/CodeGen/X86/select_const.ll
290

Doing it in selectLEAAddr doesn't work as the score doesn't get high enough.

deadalnix added inline comments.Sun, Aug 7, 6:26 PM
llvm/test/CodeGen/X86/memcmp.ll
371–372

In both cases here, cmpl %edx, %ecx seems to be recomputed for no reason (?) It seems to be able to reuse cmpl %ecx, %eax in length5 and cmpw %dx, %cx in length3, at least before this diff.

Is there a reason why this isn't the case here? I'm not quite sure how memcmp is being lowered, and -debug really isn't useful here. @gchatelet , you were looking for ways to improve memcmp, I think there is a low hanging fruit somewhere in there.

pengfei added inline comments.Sun, Aug 7, 6:43 PM
llvm/test/CodeGen/X86/memcmp.ll
371–372

xor will change EFLAGS, so we need to recomputed to get the correct EFLAGS.

deadalnix added inline comments.Sun, Aug 7, 7:05 PM
llvm/test/CodeGen/X86/memcmp.ll
371–372

Sure, but the xor itself doesn't seem necessary. For instance, length5 does:

setae %al
movzbl %al, %eax

Which does away witth he need for the xor, with in turn does away with the need to recompute the cmpl. Both function do the same thing in that block, there is no reason to have different codegen.

please can you rebase this against trunk latest?

RKSimon added inline comments.Wed, Aug 10, 12:13 PM
llvm/test/CodeGen/X86/select_const.ll
204

Comment doesn't match select_lea_2 (but the others are still OK).