[PATCH] D113948: [DAGCombiner] Prevent unfoldMaskedMerge from creating an AND with two inverted inputs.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 15 15:21:31 PST 2021
craig.topper created this revision.
craig.topper added reviewers: jrtc27, spatel, lebedev.ri.
Herald added subscribers: luke957, ecnelises, luismarques, pengfei, s.egerton, PkmX, simoncook, hiraditya.
craig.topper requested review of this revision.
Herald added a project: LLVM.
It's possible that the mask is already a NOT. At least if InstCombine
hasn't canonicalized the input. In that case we will form an ANDN with
X instead of with Y. So we don't need to worry about Y being a constant.
We might need to check that X isn't a constant instead, but we don't
have a test case for that yet.
This fixes a size regression found when trying to enable this combine
for RISCV in D113937 <https://reviews.llvm.org/D113937>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D113948
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/X86/unfold-masked-merge-scalar-variablemask.ll
Index: llvm/test/CodeGen/X86/unfold-masked-merge-scalar-variablemask.ll
===================================================================
--- llvm/test/CodeGen/X86/unfold-masked-merge-scalar-variablemask.ll
+++ llvm/test/CodeGen/X86/unfold-masked-merge-scalar-variablemask.ll
@@ -705,10 +705,9 @@
;
; CHECK-BMI-LABEL: in_constant_varx_42_invmask:
; CHECK-BMI: # %bb.0:
-; CHECK-BMI-NEXT: notl %edx
-; CHECK-BMI-NEXT: andnl %edx, %edi, %eax
-; CHECK-BMI-NEXT: orl $42, %edx
-; CHECK-BMI-NEXT: andnl %edx, %eax, %eax
+; CHECK-BMI-NEXT: andnl %edi, %edx, %eax
+; CHECK-BMI-NEXT: andl $42, %edx
+; CHECK-BMI-NEXT: orl %edx, %eax
; CHECK-BMI-NEXT: retq
%notmask = xor i32 %mask, -1
%n0 = xor i32 %x, 42 ; %x
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -7778,8 +7778,10 @@
SDLoc DL(N);
- // If Y is a constant, check that 'andn' works with immediates.
- if (!TLI.hasAndNot(Y)) {
+ // If Y is a constant, check that 'andn' works with immediates. Unless M is
+ // a not that would already allow ANDN to be used.
+ // FIXME: If M is a not, do we need to check if X is a constant?
+ if (!TLI.hasAndNot(Y) && !isBitwiseNot(M)) {
assert(TLI.hasAndNot(X) && "Only mask is a variable? Unreachable.");
// If not, we need to do a bit more work to make sure andn is still used.
SDValue NotX = DAG.getNOT(DL, X, VT);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113948.387420.patch
Type: text/x-patch
Size: 1549 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211115/41d41876/attachment.bin>
More information about the llvm-commits
mailing list