为什么clflush需要+m常量

Why does clflush needs +m constant

我发现 in Linux kernel, the clflush function 实现为

asm volatile("clflush %0" : "+m" (*(volatile char __force *)__p));

不太明白这里为什么要用+m?

按我的理解,不应该实现为

asm volatile ("clflush (%0)" :: "r"(p));

指令的任何一种形式都有效,因为它们都引用相同的地址。但是,通过使用 +m 作为约束,它可以确保对代码进行的任何优化(因为该函数是内联的)不会假设存储在指针 __p 中的数据被保留。换句话说,它可以防止无效优化。