[PATCH] D157910: [DAGCombiner] Fold trunc(undef) -> undef.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 14 13:02:37 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6299650f9788: [DAGCombiner] Fold trunc(undef) -> undef. (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157910/new/

https://reviews.llvm.org/D157910

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/test/CodeGen/RISCV/pr64503.ll


Index: llvm/test/CodeGen/RISCV/pr64503.ll
===================================================================
--- llvm/test/CodeGen/RISCV/pr64503.ll
+++ llvm/test/CodeGen/RISCV/pr64503.ll
@@ -4,12 +4,8 @@
 define i1 @f(i64 %LGV1) {
 ; CHECK-LABEL: f:
 ; CHECK:       # %bb.0:
-; CHECK-NEXT:    li a0, 1
-; CHECK-NEXT:    beqz a1, .LBB0_2
-; CHECK-NEXT:  # %bb.1:
-; CHECK-NEXT:    snez a0, a1
+; CHECK-NEXT:    sltu a0, a0, a1
 ; CHECK-NEXT:    xori a0, a0, 1
-; CHECK-NEXT:  .LBB0_2:
 ; CHECK-NEXT:    ret
   %B1 = xor i64 %LGV1, %LGV1
   %B2 = srem i64 1, %B1
@@ -21,11 +17,8 @@
 define i64 @g(ptr %A, i64 %0) {
 ; CHECK-LABEL: g:
 ; CHECK:       # %bb.0:
-; CHECK-NEXT:    li a0, 1
-; CHECK-NEXT:    beqz a2, .LBB1_2
-; CHECK-NEXT:  # %bb.1:
-; CHECK-NEXT:    slti a0, a2, 1
-; CHECK-NEXT:  .LBB1_2:
+; CHECK-NEXT:    slt a0, a0, a2
+; CHECK-NEXT:    xori a0, a0, 1
 ; CHECK-NEXT:    sb a0, 0(zero)
 ; CHECK-NEXT:    ret
   store i64 poison, ptr %A, align 4
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -14340,9 +14340,9 @@
   EVT SrcVT = N0.getValueType();
   bool isLE = DAG.getDataLayout().isLittleEndian();
 
-  // noop truncate
-  if (SrcVT == VT)
-    return N0;
+  // trunc(undef) = undef
+  if (N0.isUndef())
+    return DAG.getUNDEF(VT);
 
   // fold (truncate (truncate x)) -> (truncate x)
   if (N0.getOpcode() == ISD::TRUNCATE)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157910.550060.patch
Type: text/x-patch
Size: 1522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230814/c31b3ff2/attachment.bin>


More information about the llvm-commits mailing list