From 557bf3835b96ef5839013b1e821a1cb869660aa3 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Wed, 22 May 2024 00:48:26 +0800 Subject: [PATCH] [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 https://github.com/llvm/llvm-project/issues/90730. --- llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 2 +- llvm/test/CodeGen/RISCV/pr90730.ll | 22 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 llvm/test/CodeGen/RISCV/pr90730.ll diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index 06f85698d296ef..05859a1f4898b8 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -1919,7 +1919,7 @@ bool RISCVTargetLowering::hasAndNotCompare(SDValue Y) const { return false; return (Subtarget.hasStdExtZbb() || Subtarget.hasStdExtZbkb()) && - !isa(Y); + (!isa(Y) || cast(Y)->isOpaque()); } bool RISCVTargetLowering::hasBitTest(SDValue X, SDValue Y) const { diff --git a/llvm/test/CodeGen/RISCV/pr90730.ll b/llvm/test/CodeGen/RISCV/pr90730.ll new file mode 100644 index 00000000000000..7c3f4b43089cb3 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/pr90730.ll @@ -0,0 +1,22 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4 +; RUN: llc < %s -mtriple=riscv64 -mattr=+zbb | FileCheck %s + +define i32 @pr90730(i32 %x, i1 %y, ptr %p) { +; CHECK-LABEL: pr90730: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: lui a1, 8 +; CHECK-NEXT: addiw a1, a1, -960 +; CHECK-NEXT: andn a0, a1, a0 +; CHECK-NEXT: sw zero, 0(a2) +; CHECK-NEXT: ret +entry: + %ext = zext i1 %y to i32 + %xor1 = xor i32 %ext, 31817 + %and1 = and i32 %xor1, %x + store i32 %and1, ptr %p, align 4 + %v = load i32, ptr %p, align 4 + %and2 = and i32 %v, 31808 + %xor2 = xor i32 %and2, 31808 + store i32 0, ptr %p, align 4 + ret i32 %xor2 +}