[llvm] 73990ff - [SCEV] Recognize binary `xor` as bit-wise `add`
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 10 06:47:01 PST 2022
Author: Roman Lebedev
Date: 2022-02-10T17:42:55+03:00
New Revision: 73990ff8a76feed51a0fa89ddeda9e33b7e45f13
URL: https://github.com/llvm/llvm-project/commit/73990ff8a76feed51a0fa89ddeda9e33b7e45f13
DIFF: https://github.com/llvm/llvm-project/commit/73990ff8a76feed51a0fa89ddeda9e33b7e45f13.diff
LOG: [SCEV] Recognize binary `xor` as bit-wise `add`
https://alive2.llvm.org/ce/z/ULuZxB
We could transparently handle wider bitwidths,
by effectively casting iN to <N x i1> and performing the `add`
bit/element -wise, the expression will be rather large,
so let's not do that for now.
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/logical-operations.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 961d6a868f28..220cf3d8da3f 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -5067,6 +5067,9 @@ static Optional<BinaryOp> MatchBinaryOp(Value *V, DominatorTree &DT) {
// Instcombine turns add of signmask into xor as a strength reduction step.
if (RHSC->getValue().isSignMask())
return BinaryOp(Instruction::Add, Op->getOperand(0), Op->getOperand(1));
+ // Binary `xor` is a bit-wise `add`.
+ if (V->getType()->isIntegerTy(1))
+ return BinaryOp(Instruction::Add, Op->getOperand(0), Op->getOperand(1));
return BinaryOp(Op);
case Instruction::LShr:
diff --git a/llvm/test/Analysis/ScalarEvolution/logical-operations.ll b/llvm/test/Analysis/ScalarEvolution/logical-operations.ll
index cc3ae1eccc06..cdca89d0e038 100644
--- a/llvm/test/Analysis/ScalarEvolution/logical-operations.ll
+++ b/llvm/test/Analysis/ScalarEvolution/logical-operations.ll
@@ -86,7 +86,7 @@ define i1 @binary_xor.i1(i1 %x, i1 %y) {
; CHECK-LABEL: 'binary_xor.i1'
; CHECK-NEXT: Classifying expressions for: @binary_xor.i1
; CHECK-NEXT: %r = xor i1 %x, %y
-; CHECK-NEXT: --> %r U: full-set S: full-set
+; CHECK-NEXT: --> (%x + %y) U: full-set S: full-set
; CHECK-NEXT: Determining loop execution counts for: @binary_xor.i1
;
%r = xor i1 %x, %y
@@ -108,11 +108,11 @@ define i1 @binary_xor.4ops.i1(i1 %x, i1 %y, i1 %z, i1 %a) {
; CHECK-LABEL: 'binary_xor.4ops.i1'
; CHECK-NEXT: Classifying expressions for: @binary_xor.4ops.i1
; CHECK-NEXT: %t0 = xor i1 %x, %y
-; CHECK-NEXT: --> %t0 U: full-set S: full-set
+; CHECK-NEXT: --> (%x + %y) U: full-set S: full-set
; CHECK-NEXT: %t1 = xor i1 %z, %a
-; CHECK-NEXT: --> %t1 U: full-set S: full-set
+; CHECK-NEXT: --> (%z + %a) U: full-set S: full-set
; CHECK-NEXT: %r = xor i1 %t0, %t1
-; CHECK-NEXT: --> %r U: full-set S: full-set
+; CHECK-NEXT: --> (%x + %y + %z + %a) U: full-set S: full-set
; CHECK-NEXT: Determining loop execution counts for: @binary_xor.4ops.i1
;
%t0 = xor i1 %x, %y
More information about the llvm-commits
mailing list