Skip to content

[InstCombine] Remove unnecessary type equality check when creating zext or trunc (NFC)#175947

Merged
antoniofrighetto merged 1 commit intollvm:mainfrom
spaits:remove-unnecessary-type-equality-checks
Jan 14, 2026
Merged

[InstCombine] Remove unnecessary type equality check when creating zext or trunc (NFC)#175947
antoniofrighetto merged 1 commit intollvm:mainfrom
spaits:remove-unnecessary-type-equality-checks

Conversation

@spaits
Copy link
Contributor

@spaits spaits commented Jan 14, 2026

This came up during discussions under PR #161101.

@spaits spaits marked this pull request as ready for review January 14, 2026 14:42
@spaits spaits requested a review from nikic as a code owner January 14, 2026 14:42
@llvmbot llvmbot added llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms labels Jan 14, 2026
@llvmbot
Copy link
Member

llvmbot commented Jan 14, 2026

@llvm/pr-subscribers-llvm-transforms

Author: Gábor Spaits (spaits)

Changes

This came up during discussions under PR #161101.


Full diff: https://github.com/llvm/llvm-project/pull/175947.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp (+2-4)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 4c70e4a6e0fe0..eee3d0f6f3e1d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3965,8 +3965,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
             Value *V = Builder.CreateBitCast(
                 Vect, Builder.getIntNTy(FTy->getNumElements()));
             Value *Res = Builder.CreateUnaryIntrinsic(Intrinsic::ctpop, V);
-            if (Res->getType() != II->getType())
-              Res = Builder.CreateZExtOrTrunc(Res, II->getType());
+            Res = Builder.CreateZExtOrTrunc(Res, II->getType());
             if (Arg != Vect &&
                 cast<Instruction>(Arg)->getOpcode() == Instruction::SExt)
               Res = Builder.CreateNeg(Res);
@@ -4041,8 +4040,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
         if (auto *VTy = dyn_cast<VectorType>(Vect->getType()))
           if (VTy->getElementType() == Builder.getInt1Ty()) {
             Value *Res = Builder.CreateAndReduce(Vect);
-            if (Res->getType() != II->getType())
-              Res = Builder.CreateZExt(Res, II->getType());
+            Res = Builder.CreateZExt(Res, II->getType());
             return replaceInstUsesWith(CI, Res);
           }
       }

@antoniofrighetto antoniofrighetto changed the title [NFC]Remove unnecessary type equality check when creating zext or trunc [InstCombine] Remove unnecessary type equality check when creating zext or trunc (NFC) Jan 14, 2026
@antoniofrighetto antoniofrighetto merged commit 3424447 into llvm:main Jan 14, 2026
16 checks passed
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Jan 18, 2026
…xt or trunc (NFC) (llvm#175947)

This came up during discussions under PR llvm#161101.
BStott6 pushed a commit to BStott6/llvm-project that referenced this pull request Jan 22, 2026
…xt or trunc (NFC) (llvm#175947)

This came up during discussions under PR llvm#161101.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants