[PATCH] D129844: [InstCombine] Relax "(X & 0xFF00) + xx00 --> (X + xx00) & 0xFF00"
Piotr Sobczak via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 15 03:38:32 PDT 2022
piotr created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
piotr requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Add m_OneUse check on X, in addition to the existing one for the AND.
In case the input expression forms part of address computations
(base_addr with offset), the transformation obstructs the original
pattern (base_addr+offset) that could naturally be handled in its
original form by the backends.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129844
Files:
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/add.ll
Index: llvm/test/Transforms/InstCombine/add.ll
===================================================================
--- llvm/test/Transforms/InstCombine/add.ll
+++ llvm/test/Transforms/InstCombine/add.ll
@@ -759,6 +759,19 @@
ret i8 %r
}
+define i8 @masked_add_multi_use(i8 %x) {
+; CHECK-LABEL: @masked_add_multi_use(
+; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], -16
+; CHECK-NEXT: [[R:%.*]] = add i8 [[AND]], 96
+; CHECK-NEXT: call void @use(i8 [[X]])
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %and = and i8 %x, -16 ; 0xf0
+ %r = add i8 %and, 96 ; 0x60
+ call void @use(i8 %x) ; extra use
+ ret i8 %r
+}
+
define i32 @test35(i32 %a) {
; CHECK-LABEL: @test35(
; CHECK-NEXT: ret i32 -1
Index: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -972,7 +972,7 @@
// If all bits affected by the add are included in a high-bit-mask, do the
// add before the mask op:
// (X & 0xFF00) + xx00 --> (X + xx00) & 0xFF00
- if (match(Op0, m_OneUse(m_And(m_Value(X), m_APInt(C2)))) &&
+ if (match(Op0, m_OneUse(m_And(m_OneUse(m_Value(X)), m_APInt(C2)))) &&
C2->isNegative() && C2->isShiftedMask() && *C == (*C & *C2)) {
Value *NewAdd = Builder.CreateAdd(X, ConstantInt::get(Ty, *C));
return BinaryOperator::CreateAnd(NewAdd, ConstantInt::get(Ty, *C2));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129844.444932.patch
Type: text/x-patch
Size: 1478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220715/329642e2/attachment.bin>
More information about the llvm-commits
mailing list