[llvm] [InstCombine] Support zext nneg in `foldLogicCastConstant` (PR #82355)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 20 05:15:46 PST 2024
https://github.com/dtcxzyw created https://github.com/llvm/llvm-project/pull/82355
This patch extends [D36234](https://reviews.llvm.org/D36234) to handle `zext nneg` instructions.
I found this while adding support for cast instructions in `getFreelyInvertedImpl`.
>From c59633ee8b99b07ff7c72edc210a816e515e51aa Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Tue, 20 Feb 2024 21:08:23 +0800
Subject: [PATCH] [InstCombine] Support zext nneg in `foldLogicCastConstant`
---
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 2 +-
llvm/test/Transforms/InstCombine/cast.ll | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index ba4649e50402af..bf8794bba8859f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -1685,7 +1685,7 @@ static Instruction *foldLogicCastConstant(BinaryOperator &Logic, CastInst *Cast,
}
}
- if (match(Cast, m_OneUse(m_SExt(m_Value(X))))) {
+ if (match(Cast, m_OneUse(m_SExtLike(m_Value(X))))) {
if (Constant *TruncC = IC.getLosslessSignedTrunc(C, SrcTy)) {
// LogicOpc (sext X), C --> sext (LogicOpc X, C)
Value *NewOp = IC.Builder.CreateBinOp(LogicOpc, X, TruncC);
diff --git a/llvm/test/Transforms/InstCombine/cast.ll b/llvm/test/Transforms/InstCombine/cast.ll
index 1cda0e503ee939..85433a99f2caec 100644
--- a/llvm/test/Transforms/InstCombine/cast.ll
+++ b/llvm/test/Transforms/InstCombine/cast.ll
@@ -748,8 +748,8 @@ define i32 @test54(i64 %A) {
define i64 @test55(i32 %A) {
; ALL-LABEL: @test55(
; ALL-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 7224
-; ALL-NEXT: [[C:%.*]] = zext nneg i32 [[TMP1]] to i64
-; ALL-NEXT: [[D:%.*]] = or disjoint i64 [[C]], -32574
+; ALL-NEXT: [[TMP2:%.*]] = or disjoint i32 [[TMP1]], -32574
+; ALL-NEXT: [[D:%.*]] = sext i32 [[TMP2]] to i64
; ALL-NEXT: ret i64 [[D]]
;
%B = trunc i32 %A to i16
More information about the llvm-commits
mailing list