[DAG] ShrinkDemandedConstant - early-out for empty DemandedBits/Elts
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 20 Jul 2023 11:11:48 +0000 (12:11 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 20 Jul 2023 11:18:10 +0000 (12:18 +0100)
Leave this to constant folding in SimplifyDemandedBits

Fixes #63975

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/test/CodeGen/X86/pr63975.ll [new file with mode: 0644]

index 11594da..65ca0e0 100644 (file)
@@ -504,6 +504,11 @@ bool TargetLowering::ShrinkDemandedConstant(SDValue Op,
   SDLoc DL(Op);
   unsigned Opcode = Op.getOpcode();
 
+  // Early-out if we've ended up calling an undemanded node, leave this to
+  // constant folding.
+  if (DemandedBits.isZero() || DemandedElts.isZero())
+    return false;
+
   // Do target-specific constant optimization.
   if (targetShrinkDemandedConstant(Op, DemandedBits, DemandedElts, TLO))
     return TLO.New.getNode();
diff --git a/llvm/test/CodeGen/X86/pr63975.ll b/llvm/test/CodeGen/X86/pr63975.ll
new file mode 100644 (file)
index 0000000..42895cb
--- /dev/null
@@ -0,0 +1,30 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-- -mattr=+sse2 | FileCheck %s
+; RUN: llc < %s -mtriple=x86_64-- -mattr=+avx2 | FileCheck %s
+
+@g = external dso_local local_unnamed_addr global i16, align 2
+@l = external dso_local local_unnamed_addr global [1 x i16], align 2
+
+define void @PR63975() {
+; CHECK-LABEL: PR63975:
+; CHECK:       # %bb.0: # %entry
+; CHECK-NEXT:    movw $4, g(%rip)
+; CHECK-NEXT:    movw $0, l(%rip)
+; CHECK-NEXT:    retq
+entry:
+  store i16 4, ptr @g, align 2
+  %i = load i16, ptr @g, align 2
+  %broadcast.splatinsert7 = insertelement <8 x i16> poison, i16 %i, i64 0
+  %broadcast.splat8 = shufflevector <8 x i16> %broadcast.splatinsert7, <8 x i16> poison, <8 x i32> zeroinitializer
+  %i1 = and <8 x i16> %broadcast.splat8, <i16 8, i16 8, i16 8, i16 8, i16 8, i16 8, i16 8, i16 8>
+  %i2 = or <8 x i16> %i1, <i16 246, i16 246, i16 246, i16 246, i16 246, i16 246, i16 246, i16 246>
+  %i3 = and <8 x i16> %broadcast.splat8, <i16 255, i16 255, i16 255, i16 255, i16 255, i16 255, i16 255, i16 255>
+  %i4 = add nuw nsw <8 x i16> %i2, %i3
+  %i5 = icmp ne <8 x i16> %i4, <i16 250, i16 250, i16 250, i16 250, i16 250, i16 250, i16 250, i16 250>
+  %i6 = zext <8 x i1> %i5 to <8 x i16>
+  %i7 = zext <8 x i1> %i5 to <8 x i16>
+  %i8 = add nuw nsw <8 x i16> %i7, %i6
+  %i9 = extractelement <8 x i16> %i8, i64 2
+  store i16 %i9, ptr @l, align 2
+  ret void
+}