Skip to content

Commit

Permalink
[InstCombine] Support zext nneg in foldLogicCastConstant (llvm#82355)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
dtcxzyw authored Feb 20, 2024
1 parent 493f101 commit 9eb399b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Transforms/InstCombine/cast.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9eb399b

Please sign in to comment.