Skip to content

Commit 9eb399b

Browse files
authored
[InstCombine] Support zext nneg in foldLogicCastConstant (#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`.
1 parent 493f101 commit 9eb399b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ static Instruction *foldLogicCastConstant(BinaryOperator &Logic, CastInst *Cast,
16851685
}
16861686
}
16871687

1688-
if (match(Cast, m_OneUse(m_SExt(m_Value(X))))) {
1688+
if (match(Cast, m_OneUse(m_SExtLike(m_Value(X))))) {
16891689
if (Constant *TruncC = IC.getLosslessSignedTrunc(C, SrcTy)) {
16901690
// LogicOpc (sext X), C --> sext (LogicOpc X, C)
16911691
Value *NewOp = IC.Builder.CreateBinOp(LogicOpc, X, TruncC);

llvm/test/Transforms/InstCombine/cast.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,8 @@ define i32 @test54(i64 %A) {
748748
define i64 @test55(i32 %A) {
749749
; ALL-LABEL: @test55(
750750
; ALL-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 7224
751-
; ALL-NEXT: [[C:%.*]] = zext nneg i32 [[TMP1]] to i64
752-
; ALL-NEXT: [[D:%.*]] = or disjoint i64 [[C]], -32574
751+
; ALL-NEXT: [[TMP2:%.*]] = or disjoint i32 [[TMP1]], -32574
752+
; ALL-NEXT: [[D:%.*]] = sext i32 [[TMP2]] to i64
753753
; ALL-NEXT: ret i64 [[D]]
754754
;
755755
%B = trunc i32 %A to i16

0 commit comments

Comments
 (0)