Skip to content

[InstCombine] Fold (trunc nuw A to i1) == (trunc nuw B to i1) to A == B #133368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7451,6 +7451,9 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
}
}

if (Instruction *Res = foldICmpTruncWithTruncOrExt(I, Q))
return Res;

if (Op0->getType()->isIntOrIntVectorTy(1))
if (Instruction *Res = canonicalizeICmpBool(I, Builder))
return Res;
Expand All @@ -7473,9 +7476,6 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
if (Instruction *Res = foldICmpUsingKnownBits(I))
return Res;

if (Instruction *Res = foldICmpTruncWithTruncOrExt(I, Q))
return Res;

// Test if the ICmpInst instruction is used exclusively by a select as
// part of a minimum or maximum operation. If so, refrain from doing
// any other folding. This helps out other analyses which understand
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/Transforms/InstCombine/icmp-of-trunc-ext.ll
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,17 @@ define i1 @trunc_equality_either(i16 %x, i16 %y) {
ret i1 %c
}

define i1 @trunc_equality_bool(i8 %a, i8 %b) {
; CHECK-LABEL: @trunc_equality_bool(
; CHECK-NEXT: [[EQ:%.*]] = icmp eq i8 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: ret i1 [[EQ]]
;
%at = trunc nuw i8 %a to i1
%bt = trunc nuw i8 %b to i1
%eq = icmp eq i1 %at, %bt
ret i1 %eq
}

define i1 @trunc_unsigned_nuw_zext(i32 %x, i8 %y) {
; CHECK-LABEL: @trunc_unsigned_nuw_zext(
; CHECK-NEXT: [[TMP1:%.*]] = zext i8 [[Y:%.*]] to i32
Expand Down
Loading