[llvm] 6299650 - [DAGCombiner] Fold trunc(undef) -> undef.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 14 13:02:34 PDT 2023
Author: Craig Topper
Date: 2023-08-14T13:02:24-07:00
New Revision: 6299650f9788c8b6cc784dbf8fe4086b552be2f1
URL: https://github.com/llvm/llvm-project/commit/6299650f9788c8b6cc784dbf8fe4086b552be2f1
DIFF: https://github.com/llvm/llvm-project/commit/6299650f9788c8b6cc784dbf8fe4086b552be2f1.diff
LOG: [DAGCombiner] Fold trunc(undef) -> undef.
We already do this in getNode, but the undef might appear during
another DAGCombine.
While here remove code for handling noop truncates. getNode checks
the types and won't a noop truncate.
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D157910
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/RISCV/pr64503.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 8f1ca4909ee3e8..7ebfecab33bc08 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -14340,9 +14340,9 @@ SDValue DAGCombiner::visitTRUNCATE(SDNode *N) {
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)
diff --git a/llvm/test/CodeGen/RISCV/pr64503.ll b/llvm/test/CodeGen/RISCV/pr64503.ll
index 921187144ffd80..63a1c03a904d8e 100644
--- a/llvm/test/CodeGen/RISCV/pr64503.ll
+++ b/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 i1 @f(i64 %LGV1) {
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
More information about the llvm-commits
mailing list