[llvm] 6fea276 - [DAGCombiner] `visitFREEZE()`: be less greedy with replacing other uses of undef
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 22 15:27:14 PST 2022
Author: Roman Lebedev
Date: 2022-12-23T02:26:36+03:00
New Revision: 6fea27662dd286e8a055aca283b9285222c19374
URL: https://github.com/llvm/llvm-project/commit/6fea27662dd286e8a055aca283b9285222c19374
DIFF: https://github.com/llvm/llvm-project/commit/6fea27662dd286e8a055aca283b9285222c19374.diff
LOG: [DAGCombiner] `visitFREEZE()`: be less greedy with replacing other uses of undef
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/X86/freeze-vector.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 3076be8292ed..567b197de90c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -14277,6 +14277,9 @@ SDValue DAGCombiner::visitFREEZE(SDNode *N) {
"Should have found maybe-poison operands.");
for (SDValue MaybePoisonOperand : MaybePoisonOperands) {
+ // Don't replace every single UNDEF everywhere with frozen UNDEF, though.
+ if (MaybePoisonOperand.getOpcode() == ISD::UNDEF)
+ continue;
// First, freeze each offending operand.
SDValue FrozenMaybePoisonOperand = DAG.getFreeze(MaybePoisonOperand);
// Then, change all other uses of unfrozen operand to use frozen operand.
@@ -14290,6 +14293,11 @@ SDValue DAGCombiner::visitFREEZE(SDNode *N) {
// Finally, recreate the node, it's operands were updated to use
// frozen operands, so we just need to use it's "original" operands.
SmallVector<SDValue> Ops(N0->op_begin(), N0->op_end());
+ // Special-handle ISD::UNDEF, each single one of them can be it's own thing.
+ for (SDValue &Op : Ops) {
+ if (Op.getOpcode() == ISD::UNDEF)
+ Op = DAG.getFreeze(Op);
+ }
// TODO: Just strip poison generating flags?
SDValue R = DAG.getNode(N0.getOpcode(), SDLoc(N0), N0->getVTList(), Ops);
assert(DAG.isGuaranteedNotToBeUndefOrPoison(R, /*PoisonOnly*/ false) &&
diff --git a/llvm/test/CodeGen/X86/freeze-vector.ll b/llvm/test/CodeGen/X86/freeze-vector.ll
index a074a77b3214..b1aa32914112 100644
--- a/llvm/test/CodeGen/X86/freeze-vector.ll
+++ b/llvm/test/CodeGen/X86/freeze-vector.ll
@@ -392,16 +392,15 @@ define void @freeze_two_buildvectors_only_one_frozen(ptr %origin0, ptr %origin1,
; X86-NEXT: movl (%edx), %edx
; X86-NEXT: andl $15, %edx
; X86-NEXT: vmovd %eax, %xmm0
-; X86-NEXT: vpinsrd $1, %edx, %xmm0, %xmm1
-; X86-NEXT: vpinsrd $2, %eax, %xmm1, %xmm1
-; X86-NEXT: vpinsrd $3, %eax, %xmm1, %xmm1
-; X86-NEXT: vmovdqa {{.*#+}} xmm2 = [7,7,7,7]
-; X86-NEXT: vpand %xmm2, %xmm1, %xmm1
-; X86-NEXT: vmovdqa %xmm1, (%ecx)
-; X86-NEXT: vpinsrd $1, %eax, %xmm0, %xmm0
-; X86-NEXT: vpinsrd $2, %edx, %xmm0, %xmm0
+; X86-NEXT: vpinsrd $1, %edx, %xmm0, %xmm0
+; X86-NEXT: vpinsrd $2, %eax, %xmm0, %xmm0
; X86-NEXT: vpinsrd $3, %eax, %xmm0, %xmm0
-; X86-NEXT: vpand %xmm2, %xmm0, %xmm0
+; X86-NEXT: vmovdqa {{.*#+}} xmm1 = [7,7,7,7]
+; X86-NEXT: vpand %xmm1, %xmm0, %xmm0
+; X86-NEXT: vmovdqa %xmm0, (%ecx)
+; X86-NEXT: vmovd %edx, %xmm0
+; X86-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,1,0,1]
+; X86-NEXT: vpand %xmm1, %xmm0, %xmm0
; X86-NEXT: vmovdqa %xmm0, (%eax)
; X86-NEXT: retl
;
@@ -410,16 +409,15 @@ define void @freeze_two_buildvectors_only_one_frozen(ptr %origin0, ptr %origin1,
; X64-NEXT: movl (%rdi), %eax
; X64-NEXT: andl $15, %eax
; X64-NEXT: vmovd %eax, %xmm0
-; X64-NEXT: vpinsrd $1, %eax, %xmm0, %xmm1
-; X64-NEXT: vpinsrd $2, %eax, %xmm1, %xmm1
-; X64-NEXT: vpinsrd $3, %eax, %xmm1, %xmm1
-; X64-NEXT: vpbroadcastd {{.*#+}} xmm2 = [7,7,7,7]
-; X64-NEXT: vpand %xmm2, %xmm1, %xmm1
-; X64-NEXT: vmovdqa %xmm1, (%rdx)
; X64-NEXT: vpinsrd $1, %eax, %xmm0, %xmm0
; X64-NEXT: vpinsrd $2, %eax, %xmm0, %xmm0
; X64-NEXT: vpinsrd $3, %eax, %xmm0, %xmm0
-; X64-NEXT: vpand %xmm2, %xmm0, %xmm0
+; X64-NEXT: vpbroadcastd {{.*#+}} xmm1 = [7,7,7,7]
+; X64-NEXT: vpand %xmm1, %xmm0, %xmm0
+; X64-NEXT: vmovdqa %xmm0, (%rdx)
+; X64-NEXT: vmovd %eax, %xmm0
+; X64-NEXT: vpbroadcastd %xmm0, %xmm0
+; X64-NEXT: vpand %xmm1, %xmm0, %xmm0
; X64-NEXT: vmovdqa %xmm0, (%rcx)
; X64-NEXT: retq
%i0.src = load i32, ptr %origin0
More information about the llvm-commits
mailing list