[PATCH] D52550: [ARM] Check for sel intrinsic use in ARM CGP
Sam Parker via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 26 07:11:07 PDT 2018
samparker created this revision.
samparker added reviewers: efriedma, john.brawn, SjoerdMeijer.
Herald added a reviewer: javed.absar.
Herald added subscribers: chrib, kristof.beyls.
During initialisation, check whether the llvm.arm.sel intrinsic is used in the current module. If it has, we conservatively choose that it would be unsafe to generate the DSP add/sub instructions that will write to the GE flags - the same flags which sel will read.
https://reviews.llvm.org/D52550
Files:
lib/Target/ARM/ARMCodeGenPrepare.cpp
test/CodeGen/ARM/arm-cgp-sel.ll
Index: test/CodeGen/ARM/arm-cgp-sel.ll
===================================================================
--- /dev/null
+++ test/CodeGen/ARM/arm-cgp-sel.ll
@@ -0,0 +1,28 @@
+; RUN: llc -mtriple=thumbv7em %s -o - | FileCheck %s
+; RUN: llc -mtriple=thumbv8m.main -mcpu=cortex-m33 -arm-enable-scalar-dsp=true %s -o - | FileCheck %s
+; RUN: llc -mtriple=thumbv8m.main -mcpu=cortex-m33 -arm-enable-scalar-dsp=true -arm-enable-scalar-dsp-imms=true %s -o - | FileCheck %s
+
+define i32 @use_sel(i32 %a, i32 %b) {
+ %1 = call i32 @llvm.arm.sel(i32 %a, i32 %b)
+ ret i32 %1
+}
+
+; Test that because the sel intrinsic is used above, we don't generate a dsp
+; sub.
+; CHECK-LABEL: dsp_disable:
+; CHECK-NOT: usub
+; CHECK-NOT: ssub
+define void @dsp_disable(i8* %in, i8* %out, i8 %compare) {
+ %first = getelementptr inbounds i8, i8* %in, i32 0
+ %second = getelementptr inbounds i8, i8* %in, i32 1
+ %ld0 = load i8, i8* %first
+ %ld1 = load i8, i8* %second
+ %xor = xor i8 %ld0, -1
+ %cmp = icmp ult i8 %compare, %ld1
+ %select = select i1 %cmp, i8 %compare, i8 %xor
+ %sub = sub i8 %ld0, %select
+ store i8 %sub, i8* %out, align 1
+ ret void
+}
+
+declare i32 @llvm.arm.sel(i32, i32)
Index: lib/Target/ARM/ARMCodeGenPrepare.cpp
===================================================================
--- lib/Target/ARM/ARMCodeGenPrepare.cpp
+++ lib/Target/ARM/ARMCodeGenPrepare.cpp
@@ -136,6 +136,7 @@
const ARMSubtarget *ST = nullptr;
IRPromoter *Promoter = nullptr;
std::set<Value*> AllVisited;
+ bool SafeToWriteGE = false;
bool isSupportedValue(Value *V);
bool isLegalToPromote(Value *V);
@@ -658,6 +659,12 @@
if (!I)
return false;
+ // Predicated on whether the sel intrinsic has been used within the module.
+ // If it has, conservatively choose to not generate any instructions that
+ // would overwrite the GE flags.
+ if (!SafeToWriteGE)
+ return false;
+
// If promotion is not safe, can we use a DSP instruction to natively
// handle the narrow type?
if (!ST->hasDSP() || !EnableDSP || !isSupportedType(I))
@@ -789,6 +796,8 @@
bool ARMCodeGenPrepare::doInitialization(Module &M) {
Promoter = new IRPromoter(&M);
+ SafeToWriteGE =
+ Intrinsic::getDeclaration(&M, Intrinsic::arm_sel)->hasNUses(0);
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52550.167128.patch
Type: text/x-patch
Size: 2286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180926/84efc976/attachment.bin>
More information about the llvm-commits
mailing list