Skip to content

Commit d6639f8

Browse files
committed
[SDAG][RISCV] Avoid folding setcc (xor C1, -1), C2, cond into setcc (xor C2, -1), C1, cond
This patch fixes llvm#64935. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D158654
1 parent 9223306 commit d6639f8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5093,7 +5093,8 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
50935093
if (isBitwiseNot(N1))
50945094
return DAG.getSetCC(dl, VT, N1.getOperand(0), N0.getOperand(0), Cond);
50955095

5096-
if (DAG.isConstantIntBuildVectorOrConstantInt(N1)) {
5096+
if (DAG.isConstantIntBuildVectorOrConstantInt(N1) &&
5097+
!DAG.isConstantIntBuildVectorOrConstantInt(N0.getOperand(0))) {
50975098
SDValue Not = DAG.getNOT(dl, N1, OpVT);
50985099
return DAG.getSetCC(dl, VT, Not, N0.getOperand(0), Cond);
50995100
}

llvm/test/CodeGen/RISCV/pr64935.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2+
; RUN: llc -mtriple=riscv32 < %s | FileCheck %s
3+
4+
define i1 @f() {
5+
; CHECK-LABEL: f:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: lui a0, 524288
8+
; CHECK-NEXT: not a0, a0
9+
; CHECK-NEXT: sltiu a0, a0, 2
10+
; CHECK-NEXT: xori a0, a0, 1
11+
; CHECK-NEXT: ret
12+
%B25 = shl i64 4294967296, -9223372036854775808
13+
%B13 = sub i64 -1, -9223372036854775808
14+
%C8 = icmp ugt i64 %B13, %B25
15+
%B5 = sub i64 0, 4294967296 ; Don't remove this instruction!
16+
ret i1 %C8
17+
}

0 commit comments

Comments
 (0)