OSDN Git Service

[ARM] fpscr read/write intrinsics not aware of each other
authorRanjeet Singh <Ranjeet.Singh@arm.com>
Fri, 3 Mar 2017 11:40:07 +0000 (11:40 +0000)
committerRanjeet Singh <Ranjeet.Singh@arm.com>
Fri, 3 Mar 2017 11:40:07 +0000 (11:40 +0000)
commit82eec824a7a9ce9595eea6704ae339d1bdd71dcb
tree0b40ce6682bbed89b79cca188db725b6469313f4
parent48b84df15d5b726ed5ea38cd78aafcd62e5d7fa2
[ARM] fpscr read/write intrinsics not aware of each other

The intrinsics __builtin_arm_get_fpscr and __builtin_arm_set_fpscr read and
write to the fpscr (Floating-Point Status and Control Register) register.

A bug exists in the __builtin_arm_get_fpscr intrinsic definition in llvm which
treats this intrinsic as a IntroNoMem which means it's not a memory access and
doesn't have any other side-effects. Having this property on this intrinsic
means that various optimizations can be done on this such as common
sub-expression elimination with other reads. This can cause issues if there has
been write to this register, e.g.

void foo(int *p) {
     p[0] = __builtin_arm_get_fpscr();
     __builtin_arm_set_fpscr(1);
     p[1] = __builtin_arm_get_fpscr();
}

in the above example the second read is currently CSE'd into the first read,
this is because llvm isn't aware that the write done by __builtin_arm_set_fpscr
effects the same register that __builtin_arm_get_fpscr reads from, to fix this
problem I've removed the property IntrNoMem so that __builtin_arm_get_fpscr is
treated as a memory access.

Differential Revision: https://reviews.llvm.org/D30542

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296865 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/IR/IntrinsicsARM.td
test/CodeGen/ARM/fpscr-intrinsics.ll [new file with mode: 0644]