Skip to content

Commit 7c080e2

Browse files
authored
[InstCombine] Avoid to create bitreverse.i1 for or of trunc to i1 (#142258)
1 parent f669b9c commit 7c080e2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4117,7 +4117,8 @@ bool llvm::recognizeBSwapOrBitReverseIdiom(
41174117
if (!MatchBSwaps && !MatchBitReversals)
41184118
return false;
41194119
Type *ITy = I->getType();
4120-
if (!ITy->isIntOrIntVectorTy() || ITy->getScalarSizeInBits() > 128)
4120+
if (!ITy->isIntOrIntVectorTy() || ITy->getScalarSizeInBits() == 1 ||
4121+
ITy->getScalarSizeInBits() > 128)
41214122
return false; // Can't do integer/elements > 128 bits.
41224123

41234124
// Try to find all the pieces corresponding to the bswap.

llvm/test/Transforms/InstCombine/or.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,3 +2035,15 @@ define i32 @or_xor_and_commuted3(i32 %x, i32 %y, i32 %z) {
20352035
%or1 = or i32 %xor, %yy
20362036
ret i32 %or1
20372037
}
2038+
2039+
define i1 @or_truncs(i8 %x) {
2040+
; CHECK-LABEL: @or_truncs(
2041+
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], 1
2042+
; CHECK-NEXT: [[OR1:%.*]] = icmp ne i8 [[TMP1]], 0
2043+
; CHECK-NEXT: ret i1 [[OR1]]
2044+
;
2045+
%trunc1 = trunc i8 %x to i1
2046+
%trunc2 = trunc i8 %x to i1
2047+
%or1 = or i1 %trunc1, %trunc2
2048+
ret i1 %or1
2049+
}

0 commit comments

Comments
 (0)