[llvm] 337215d - [DAG] ABD is not reassociative

David Green via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 1 08:22:19 PST 2023


Author: David Green
Date: 2023-03-01T16:22:13Z
New Revision: 337215ddf93f074575e530d796589b67044d0406

URL: https://github.com/llvm/llvm-project/commit/337215ddf93f074575e530d796589b67044d0406
DIFF: https://github.com/llvm/llvm-project/commit/337215ddf93f074575e530d796589b67044d0406.diff

LOG: [DAG] ABD is not reassociative

I'm not sure how I missed this in the testing, but as far as I understand
whilst ABDS and ABDU are commutive they are not associative. This patch
disables reassociateOps from visitABD, fixing the problems found in #61069.
ABDU: https://alive2.llvm.org/ce/z/eiT5QG
ABDS: https://alive2.llvm.org/ce/z/HzE29l

Differential Revision: https://reviews.llvm.org/D145064

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    llvm/test/CodeGen/AArch64/abd-combine.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index d05884365c960..3da873dec1c2b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -5073,9 +5073,6 @@ SDValue DAGCombiner::visitABD(SDNode *N) {
   // fold (abd c1, c2)
   if (SDValue C = DAG.FoldConstantArithmetic(Opcode, DL, VT, {N0, N1}))
     return C;
-  // reassociate if possible
-  if (SDValue C = reassociateOps(Opcode, DL, N0, N1, N->getFlags()))
-    return C;
 
   // canonicalize constant to RHS.
   if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&

diff  --git a/llvm/test/CodeGen/AArch64/abd-combine.ll b/llvm/test/CodeGen/AArch64/abd-combine.ll
index e7fbbfe64b9a6..dad3fd08a7b9a 100644
--- a/llvm/test/CodeGen/AArch64/abd-combine.ll
+++ b/llvm/test/CodeGen/AArch64/abd-combine.ll
@@ -321,8 +321,10 @@ define <8 x i16> @abdu_i_undef(<8 x i16> %t, <8 x i16> %src1) {
 define <8 x i16> @abdu_i_reassoc(<8 x i16> %src1) {
 ; CHECK-LABEL: abdu_i_reassoc:
 ; CHECK:       // %bb.0:
-; CHECK-NEXT:    movi v1.8h, #2
+; CHECK-NEXT:    movi v1.8h, #3
+; CHECK-NEXT:    movi v2.8h, #1
 ; CHECK-NEXT:    uabd v0.8h, v0.8h, v1.8h
+; CHECK-NEXT:    uabd v0.8h, v0.8h, v2.8h
 ; CHECK-NEXT:    ret
   %r1 = call <8 x i16> @llvm.aarch64.neon.uabd.v8i16(<8 x i16> %src1, <8 x i16> <i16 3, i16 3, i16 3, i16 3, i16 3, i16 3, i16 3, i16 3>)
   %result = call <8 x i16> @llvm.aarch64.neon.uabd.v8i16(<8 x i16> %r1, <8 x i16> <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>)
@@ -539,8 +541,10 @@ define <8 x i16> @abds_i_undef(<8 x i16> %t, <8 x i16> %src1) {
 define <8 x i16> @abds_i_reassoc(<8 x i16> %src1) {
 ; CHECK-LABEL: abds_i_reassoc:
 ; CHECK:       // %bb.0:
-; CHECK-NEXT:    movi v1.8h, #2
+; CHECK-NEXT:    movi v1.8h, #3
+; CHECK-NEXT:    movi v2.8h, #1
 ; CHECK-NEXT:    sabd v0.8h, v0.8h, v1.8h
+; CHECK-NEXT:    sabd v0.8h, v0.8h, v2.8h
 ; CHECK-NEXT:    ret
   %r1 = call <8 x i16> @llvm.aarch64.neon.sabd.v8i16(<8 x i16> %src1, <8 x i16> <i16 3, i16 3, i16 3, i16 3, i16 3, i16 3, i16 3, i16 3>)
   %result = call <8 x i16> @llvm.aarch64.neon.sabd.v8i16(<8 x i16> %r1, <8 x i16> <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>)


        


More information about the llvm-commits mailing list