Skip to content

Commit

Permalink
[DAGCombiner] Fold trunc(undef) -> undef.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
topperc committed Aug 14, 2023
1 parent a63bd7e commit 6299650
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 3 additions & 10 deletions llvm/test/CodeGen/RISCV/pr64503.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6299650

Please sign in to comment.