[llvm] f45c1e4 - [InstCombine] Change operand order in recursive and/or of icmps fold
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon May 23 08:31:00 PDT 2022
Author: Nikita Popov
Date: 2022-05-23T17:29:33+02:00
New Revision: f45c1e436e47f18cbef83b1dffa15fb7f234b357
URL: https://github.com/llvm/llvm-project/commit/f45c1e436e47f18cbef83b1dffa15fb7f234b357
DIFF: https://github.com/llvm/llvm-project/commit/f45c1e436e47f18cbef83b1dffa15fb7f234b357.diff
LOG: [InstCombine] Change operand order in recursive and/or of icmps fold
The order obviously doesn't matter for bitwise and/or, but would
matter for logical and/or, so change it to preserve the original
order.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/and-or-icmps.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index f442cf10bc24..107a57f409a9 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -1995,7 +1995,7 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
return replaceInstUsesWith(I, Builder.CreateAnd(Res, Y));
if (auto *Cmp = dyn_cast<ICmpInst>(Y))
if (Value *Res = foldAndOrOfICmps(LHS, Cmp, I, /* IsAnd */ true))
- return replaceInstUsesWith(I, Builder.CreateAnd(Res, X));
+ return replaceInstUsesWith(I, Builder.CreateAnd(X, Res));
}
if (RHS && match(Op0, m_OneUse(m_And(m_Value(X), m_Value(Y))))) {
if (auto *Cmp = dyn_cast<ICmpInst>(X))
@@ -2003,7 +2003,7 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
return replaceInstUsesWith(I, Builder.CreateAnd(Res, Y));
if (auto *Cmp = dyn_cast<ICmpInst>(Y))
if (Value *Res = foldAndOrOfICmps(Cmp, RHS, I, /* IsAnd */ true))
- return replaceInstUsesWith(I, Builder.CreateAnd(Res, X));
+ return replaceInstUsesWith(I, Builder.CreateAnd(X, Res));
}
}
@@ -2794,7 +2794,7 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
return replaceInstUsesWith(I, Builder.CreateOr(Res, Y));
if (auto *Cmp = dyn_cast<ICmpInst>(Y))
if (Value *Res = foldAndOrOfICmps(LHS, Cmp, I, /* IsAnd */ false))
- return replaceInstUsesWith(I, Builder.CreateOr(Res, X));
+ return replaceInstUsesWith(I, Builder.CreateOr(X, Res));
}
if (RHS && match(Op0, m_OneUse(m_Or(m_Value(X), m_Value(Y))))) {
if (auto *Cmp = dyn_cast<ICmpInst>(X))
@@ -2802,7 +2802,7 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
return replaceInstUsesWith(I, Builder.CreateOr(Res, Y));
if (auto *Cmp = dyn_cast<ICmpInst>(Y))
if (Value *Res = foldAndOrOfICmps(Cmp, RHS, I, /* IsAnd */ false))
- return replaceInstUsesWith(I, Builder.CreateOr(Res, X));
+ return replaceInstUsesWith(I, Builder.CreateOr(X, Res));
}
}
diff --git a/llvm/test/Transforms/InstCombine/and-or-icmps.ll b/llvm/test/Transforms/InstCombine/and-or-icmps.ll
index 8ba8586dcbb5..7f0792da52f6 100644
--- a/llvm/test/Transforms/InstCombine/and-or-icmps.ll
+++ b/llvm/test/Transforms/InstCombine/and-or-icmps.ll
@@ -1281,7 +1281,7 @@ define i1 @bitwise_and_bitwise_and_icmps(i8 %x, i8 %y) {
; CHECK-LABEL: @bitwise_and_bitwise_and_icmps(
; CHECK-NEXT: [[C1:%.*]] = icmp eq i8 [[Y:%.*]], 42
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
-; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[C1]]
+; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[C1]], [[TMP1]]
; CHECK-NEXT: ret i1 [[TMP2]]
;
%c1 = icmp eq i8 %y, 42
@@ -1296,7 +1296,7 @@ define i1 @bitwise_and_bitwise_and_icmps_comm1(i8 %x, i8 %y) {
; CHECK-LABEL: @bitwise_and_bitwise_and_icmps_comm1(
; CHECK-NEXT: [[C1:%.*]] = icmp eq i8 [[Y:%.*]], 42
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
-; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[C1]]
+; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[C1]], [[TMP1]]
; CHECK-NEXT: ret i1 [[TMP2]]
;
%c1 = icmp eq i8 %y, 42
@@ -1409,7 +1409,7 @@ define i1 @logical_and_bitwise_and_icmps(i8 %x, i8 %y) {
; CHECK-LABEL: @logical_and_bitwise_and_icmps(
; CHECK-NEXT: [[C1:%.*]] = icmp eq i8 [[Y:%.*]], 42
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
-; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[C1]]
+; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[C1]], [[TMP1]]
; CHECK-NEXT: ret i1 [[TMP2]]
;
%c1 = icmp eq i8 %y, 42
@@ -1539,7 +1539,7 @@ define i1 @bitwise_or_bitwise_or_icmps(i8 %x, i8 %y) {
; CHECK-LABEL: @bitwise_or_bitwise_or_icmps(
; CHECK-NEXT: [[C1:%.*]] = icmp eq i8 [[Y:%.*]], 42
; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i8 [[X:%.*]], 0
-; CHECK-NEXT: [[TMP2:%.*]] = or i1 [[TMP1]], [[C1]]
+; CHECK-NEXT: [[TMP2:%.*]] = or i1 [[C1]], [[TMP1]]
; CHECK-NEXT: ret i1 [[TMP2]]
;
%c1 = icmp eq i8 %y, 42
@@ -1554,7 +1554,7 @@ define i1 @bitwise_or_bitwise_or_icmps_comm1(i8 %x, i8 %y) {
; CHECK-LABEL: @bitwise_or_bitwise_or_icmps_comm1(
; CHECK-NEXT: [[C1:%.*]] = icmp eq i8 [[Y:%.*]], 42
; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i8 [[X:%.*]], 0
-; CHECK-NEXT: [[TMP2:%.*]] = or i1 [[TMP1]], [[C1]]
+; CHECK-NEXT: [[TMP2:%.*]] = or i1 [[C1]], [[TMP1]]
; CHECK-NEXT: ret i1 [[TMP2]]
;
%c1 = icmp eq i8 %y, 42
@@ -1667,7 +1667,7 @@ define i1 @logical_or_bitwise_or_icmps(i8 %x, i8 %y) {
; CHECK-LABEL: @logical_or_bitwise_or_icmps(
; CHECK-NEXT: [[C1:%.*]] = icmp eq i8 [[Y:%.*]], 42
; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i8 [[X:%.*]], 0
-; CHECK-NEXT: [[TMP2:%.*]] = or i1 [[TMP1]], [[C1]]
+; CHECK-NEXT: [[TMP2:%.*]] = or i1 [[C1]], [[TMP1]]
; CHECK-NEXT: ret i1 [[TMP2]]
;
%c1 = icmp eq i8 %y, 42
More information about the llvm-commits
mailing list