Skip to content

Commit 6241f48

Browse files
committed
[InstCombine] Avoid to create bitreverse.i1 for or of trunc to i1
1 parent 4bcea68 commit 6241f48

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,8 +2038,8 @@ define i32 @or_xor_and_commuted3(i32 %x, i32 %y, i32 %z) {
20382038

20392039
define i1 @or_truncs(i8 %x) {
20402040
; CHECK-LABEL: @or_truncs(
2041-
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
2042-
; CHECK-NEXT: [[OR1:%.*]] = call i1 @llvm.bitreverse.i1(i1 [[TRUNC]])
2041+
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], 1
2042+
; CHECK-NEXT: [[OR1:%.*]] = icmp ne i8 [[TMP1]], 0
20432043
; CHECK-NEXT: ret i1 [[OR1]]
20442044
;
20452045
%trunc1 = trunc i8 %x to i1

0 commit comments

Comments
 (0)