[llvm] [InstCombine] Avoid to create bitreverse.i1 for or of trunc to i1 (PR #142258)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 30 23:55:20 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Andreas Jonson (andjo403)
<details>
<summary>Changes</summary>
Avoid to create bitreverse.i1 as it hinder optimizations due to there is less optimizations for bitreverse and also is a bit strange to create a i1 bitreverse
this change avoids this transform a couple of times in llvm-opt-benchmark.
---
Full diff: https://github.com/llvm/llvm-project/pull/142258.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Utils/Local.cpp (+2-1)
- (modified) llvm/test/Transforms/InstCombine/or.ll (+12)
``````````diff
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index fe1391a501b43..a0618726ac0ac 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -4117,7 +4117,8 @@ bool llvm::recognizeBSwapOrBitReverseIdiom(
if (!MatchBSwaps && !MatchBitReversals)
return false;
Type *ITy = I->getType();
- if (!ITy->isIntOrIntVectorTy() || ITy->getScalarSizeInBits() > 128)
+ if (!ITy->isIntOrIntVectorTy() || ITy->getScalarSizeInBits() == 1 ||
+ ITy->getScalarSizeInBits() > 128)
return false; // Can't do integer/elements > 128 bits.
// Try to find all the pieces corresponding to the bswap.
diff --git a/llvm/test/Transforms/InstCombine/or.ll b/llvm/test/Transforms/InstCombine/or.ll
index 95f89e4ce11cd..a5cc933278982 100644
--- a/llvm/test/Transforms/InstCombine/or.ll
+++ b/llvm/test/Transforms/InstCombine/or.ll
@@ -2035,3 +2035,15 @@ define i32 @or_xor_and_commuted3(i32 %x, i32 %y, i32 %z) {
%or1 = or i32 %xor, %yy
ret i32 %or1
}
+
+define i1 @or_truncs(i8 %x) {
+; CHECK-LABEL: @or_truncs(
+; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], 1
+; CHECK-NEXT: [[OR1:%.*]] = icmp ne i8 [[TMP1]], 0
+; CHECK-NEXT: ret i1 [[OR1]]
+;
+ %trunc1 = trunc i8 %x to i1
+ %trunc2 = trunc i8 %x to i1
+ %or1 = or i1 %trunc1, %trunc2
+ ret i1 %or1
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/142258
More information about the llvm-commits
mailing list