From 92f7a6b5898f3686a7e45b5a6129d560b07da6c2 Mon Sep 17 00:00:00 2001
From: Piotr Fusik
Date: Mon, 17 Mar 2025 16:14:23 +0100
Subject: [PATCH] [RISCV] Sink NOT to be fold into ANDN/ORN/XNOR/VANDN
Undoes a negation being hoisted out of a loop, so that it can be fold
into an inverted bitwise operation in the loop.
Implements #108840 on RISC-V
---
.../Target/RISCV/RISCVTargetTransformInfo.cpp | 33 ++
llvm/test/CodeGen/RISCV/rv32zbb-zbkb.ll | 318 ++++++++++++------
llvm/test/CodeGen/RISCV/rv64zbb-zbkb.ll | 288 ++++++++++------
llvm/test/CodeGen/RISCV/rvv/vandn-sdnode.ll | 299 ++++++++++------
4 files changed, 627 insertions(+), 311 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 11a658758a9cb..1060093043278 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -2779,6 +2779,39 @@ bool RISCVTTIImpl::isProfitableToSinkOperands(
Instruction *I, SmallVectorImpl