[llvm] [DAG] SelectionDAG::canCreateUndefOrPoison - AVGFLOORU/AVGCEILU don't create undef/poison (PR #157056)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 5 01:59:42 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: Simon Pilgrim (RKSimon)

<details>
<summary>Changes</summary>

AVGFLOORU: https://alive2.llvm.org/ce/z/4pfi4i
AVGCEILU: https://alive2.llvm.org/ce/z/CGvWiA

The signed variants are still proving annoying to get test cases to work properly

Fixes half of #<!-- -->147696

---
Full diff: https://github.com/llvm/llvm-project/pull/157056.diff


2 Files Affected:

- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+2) 
- (modified) llvm/test/CodeGen/AArch64/freeze.ll (-6) 


``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 9668d253d52ae..63a9f8bc2c615 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5670,6 +5670,8 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
   case ISD::UADDSAT:
   case ISD::SSUBSAT:
   case ISD::USUBSAT:
+  case ISD::AVGFLOORU:
+  case ISD::AVGCEILU:
   case ISD::MULHU:
   case ISD::MULHS:
   case ISD::ABDU:
diff --git a/llvm/test/CodeGen/AArch64/freeze.ll b/llvm/test/CodeGen/AArch64/freeze.ll
index 2a33a4c061dce..7a9d6b7e52457 100644
--- a/llvm/test/CodeGen/AArch64/freeze.ll
+++ b/llvm/test/CodeGen/AArch64/freeze.ll
@@ -430,16 +430,13 @@ define <8 x i16> @freeze_abds(<8 x i16> %a, <8 x i16> %b) {
   ret <8 x i16> %r
 }
 
-; TODO: Unnecessary final and
 define <8 x i16> @freeze_uhadd(<8 x i16> %a0, <8 x i16> %a1) {
 ; CHECK-LABEL: freeze_uhadd:
 ; CHECK:       // %bb.0:
 ; CHECK-NEXT:    movi v2.8h, #15
 ; CHECK-NEXT:    and v0.16b, v0.16b, v2.16b
 ; CHECK-NEXT:    and v1.16b, v1.16b, v2.16b
-; CHECK-NEXT:    movi v2.8h, #31
 ; CHECK-NEXT:    uhadd v0.8h, v0.8h, v1.8h
-; CHECK-NEXT:    and v0.16b, v0.16b, v2.16b
 ; CHECK-NEXT:    ret
   %m0 = and <8 x i16> %a0, splat (i16 15)
   %m1 = and <8 x i16> %a1, splat (i16 15)
@@ -449,16 +446,13 @@ define <8 x i16> @freeze_uhadd(<8 x i16> %a0, <8 x i16> %a1) {
   ret <8 x i16> %masked
 }
 
-; TODO: Unnecessary final and
 define <8 x i16> @freeze_urhadd(<8 x i16> %a0, <8 x i16> %a1) {
 ; CHECK-LABEL: freeze_urhadd:
 ; CHECK:       // %bb.0:
 ; CHECK-NEXT:    movi v2.8h, #15
 ; CHECK-NEXT:    and v0.16b, v0.16b, v2.16b
 ; CHECK-NEXT:    and v1.16b, v1.16b, v2.16b
-; CHECK-NEXT:    movi v2.8h, #31
 ; CHECK-NEXT:    urhadd v0.8h, v0.8h, v1.8h
-; CHECK-NEXT:    and v0.16b, v0.16b, v2.16b
 ; CHECK-NEXT:    ret
   %m0 = and <8 x i16> %a0, splat (i16 15)
   %m1 = and <8 x i16> %a1, splat (i16 15)

``````````

</details>


https://github.com/llvm/llvm-project/pull/157056


More information about the llvm-commits mailing list