diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 76020d2b1dbf4..e75b4026d5424 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -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; @@ -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 diff --git a/llvm/test/Transforms/InstCombine/icmp-of-trunc-ext.ll b/llvm/test/Transforms/InstCombine/icmp-of-trunc-ext.ll index 2c2de5dbf09f6..aeb70a636682f 100644 --- a/llvm/test/Transforms/InstCombine/icmp-of-trunc-ext.ll +++ b/llvm/test/Transforms/InstCombine/icmp-of-trunc-ext.ll @@ -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