[PATCH] D103801: [InstCombine] Support negation of scalable-vector splats
Fraser Cormack via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 7 04:02:20 PDT 2021
frasercrmck created this revision.
frasercrmck added reviewers: RKSimon, craig.topper, sdesmalen.
Herald added a subscriber: hiraditya.
frasercrmck requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This patch is an extension of D103421 <https://reviews.llvm.org/D103421>. It allows the InstCombiner to
generate the negated form of integer scalable-vector splats. It can
technically handle fixed-length vectors too but those are completely
covered by the preceding logic.
This enables extra combining opportunities for scalable vector types.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D103801
Files:
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/sub.ll
Index: llvm/test/Transforms/InstCombine/sub.ll
===================================================================
--- llvm/test/Transforms/InstCombine/sub.ll
+++ llvm/test/Transforms/InstCombine/sub.ll
@@ -839,11 +839,9 @@
ret <2 x i32> %sub
}
-; FIXME: We're not giving this new 'add' a nsw flag as in the fixed-length case
-; above. We need to be able catch the splat with dyn_castNegVal.
define <vscale x 2 x i32> @test44scalablevec(<vscale x 2 x i32> %x) {
; CHECK-LABEL: @test44scalablevec(
-; CHECK-NEXT: [[SUB:%.*]] = add <vscale x 2 x i32> [[X:%.*]], shufflevector (<vscale x 2 x i32> insertelement (<vscale x 2 x i32> undef, i32 -32768, i32 0), <vscale x 2 x i32> undef, <vscale x 2 x i32> zeroinitializer)
+; CHECK-NEXT: [[SUB:%.*]] = add nsw <vscale x 2 x i32> [[X:%.*]], shufflevector (<vscale x 2 x i32> insertelement (<vscale x 2 x i32> undef, i32 -32768, i32 0), <vscale x 2 x i32> undef, <vscale x 2 x i32> zeroinitializer)
; CHECK-NEXT: ret <vscale x 2 x i32> [[SUB]]
;
%sub = sub nsw <vscale x 2 x i32> %x, shufflevector (<vscale x 2 x i32> insertelement (<vscale x 2 x i32> undef, i32 32768, i32 0), <vscale x 2 x i32> undef, <vscale x 2 x i32> zeroinitializer)
Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -924,6 +924,12 @@
return ConstantExpr::getNeg(CV);
}
+ // Negate integer vector splats.
+ if (auto *CV = dyn_cast<Constant>(V))
+ if (CV->getType()->isVectorTy() &&
+ CV->getType()->getScalarType()->isIntegerTy() && CV->getSplatValue())
+ return ConstantExpr::getNeg(CV);
+
return nullptr;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103801.350235.patch
Type: text/x-patch
Size: 1786 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210607/e2d9fd21/attachment.bin>
More information about the llvm-commits
mailing list