Skip to content

Commit 557bf38

Browse files
authored
[RISCV][ISel] Allow opaque constants in hasAndNotCompare (#92926)
See the following code: https://github.com/llvm/llvm-project/blob/4ae896fe979b7db501cabde4b6b3504478958682/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L9334-L9357 > Combining: t47: i64 = xor t43, OpaqueConstant:i64<31808> X: i64 = Constant<0> Y: i64 = OpaqueConstant<31808> The assertion failed because both `X` and `Y` are constants. This patch allows opaque constants in `hasAndNotCompare` to fix the issue. Fixes #90730.
1 parent 0c8bc08 commit 557bf38

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,7 @@ bool RISCVTargetLowering::hasAndNotCompare(SDValue Y) const {
19191919
return false;
19201920

19211921
return (Subtarget.hasStdExtZbb() || Subtarget.hasStdExtZbkb()) &&
1922-
!isa<ConstantSDNode>(Y);
1922+
(!isa<ConstantSDNode>(Y) || cast<ConstantSDNode>(Y)->isOpaque());
19231923
}
19241924

19251925
bool RISCVTargetLowering::hasBitTest(SDValue X, SDValue Y) const {

llvm/test/CodeGen/RISCV/pr90730.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc < %s -mtriple=riscv64 -mattr=+zbb | FileCheck %s
3+
4+
define i32 @pr90730(i32 %x, i1 %y, ptr %p) {
5+
; CHECK-LABEL: pr90730:
6+
; CHECK: # %bb.0: # %entry
7+
; CHECK-NEXT: lui a1, 8
8+
; CHECK-NEXT: addiw a1, a1, -960
9+
; CHECK-NEXT: andn a0, a1, a0
10+
; CHECK-NEXT: sw zero, 0(a2)
11+
; CHECK-NEXT: ret
12+
entry:
13+
%ext = zext i1 %y to i32
14+
%xor1 = xor i32 %ext, 31817
15+
%and1 = and i32 %xor1, %x
16+
store i32 %and1, ptr %p, align 4
17+
%v = load i32, ptr %p, align 4
18+
%and2 = and i32 %v, 31808
19+
%xor2 = xor i32 %and2, 31808
20+
store i32 0, ptr %p, align 4
21+
ret i32 %xor2
22+
}

0 commit comments

Comments
 (0)