[llvm] 3e1d2c3 - [InstCombine] Fix or of commuted foldable predicates
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 22 03:33:32 PDT 2022
Author: Nikita Popov
Date: 2022-04-22T12:31:26+02:00
New Revision: 3e1d2c352c1fb9fb7022344fb4e5639b4f5b1c45
URL: https://github.com/llvm/llvm-project/commit/3e1d2c352c1fb9fb7022344fb4e5639b4f5b1c45
DIFF: https://github.com/llvm/llvm-project/commit/3e1d2c352c1fb9fb7022344fb4e5639b4f5b1c45.diff
LOG: [InstCombine] Fix or of commuted foldable predicates
1d90e530442477de247dcb613f5176fe7e9beded switch this code to store
the predicates and operands in variables, but retained a
swapOperands() call here. Thus the commuted cases were no longer
folded. Additionally, as the change was not reported, the next
InstCombine iteration would not pick it up either.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/or.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index b8dba03e5e689..d596033ec22c2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2580,11 +2580,12 @@ Value *InstCombinerImpl::foldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS,
// (icmp1 A, B) | (icmp2 A, B) --> (icmp3 A, B)
if (predicatesFoldable(PredL, PredR)) {
- if (LHS0 == RHS1 && LHS1 == RHS0)
- LHS->swapOperands();
+ if (LHS0 == RHS1 && LHS1 == RHS0) {
+ PredL = ICmpInst::getSwappedPredicate(PredL);
+ std::swap(LHS0, LHS1);
+ }
if (LHS0 == RHS0 && LHS1 == RHS1) {
- unsigned Code =
- getICmpCode(LHS->getPredicate()) | getICmpCode(RHS->getPredicate());
+ unsigned Code = getICmpCode(PredL) | getICmpCode(PredR);
bool IsSigned = LHS->isSigned() || RHS->isSigned();
return getNewICmpValue(Code, IsSigned, LHS0, LHS1, Builder);
}
diff --git a/llvm/test/Transforms/InstCombine/or.ll b/llvm/test/Transforms/InstCombine/or.ll
index 09d6780c917d8..b1ff6830a3783 100644
--- a/llvm/test/Transforms/InstCombine/or.ll
+++ b/llvm/test/Transforms/InstCombine/or.ll
@@ -39,10 +39,8 @@ define i1 @test14(i32 %A, i32 %B) {
define i1 @test14_commuted(i32 %A, i32 %B) {
; CHECK-LABEL: @test14_commuted(
-; CHECK-NEXT: [[C1:%.*]] = icmp ugt i32 [[B:%.*]], [[A:%.*]]
-; CHECK-NEXT: [[C2:%.*]] = icmp ult i32 [[B]], [[A]]
-; CHECK-NEXT: [[D:%.*]] = or i1 [[C1]], [[C2]]
-; CHECK-NEXT: ret i1 [[D]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i32 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%C1 = icmp ult i32 %A, %B
%C2 = icmp ult i32 %B, %A
More information about the llvm-commits
mailing list