OSDN Git Service

[EarlyCSE] Improve EarlyCSE of some absolute value cases.
authorCraig Topper <craig.topper@intel.com>
Mon, 21 May 2018 18:42:42 +0000 (18:42 +0000)
committerCraig Topper <craig.topper@intel.com>
Mon, 21 May 2018 18:42:42 +0000 (18:42 +0000)
commit77438c3c98c0901fa9ef56f78bdefccedc16fcc4
treeb6ea6e3456f820e0054716a4a6a64379cd344093
parent2e125e8f4642e253a4a1b11426e1b1da90bfc8d4
[EarlyCSE] Improve EarlyCSE of some absolute value cases.

Change matchSelectPattern to return X and -X for ABS/NABS in a well defined order. Adjust EarlyCSE to account for this. Ensure the SPF result is some kind of min/max and not abs/nabs in one place in InstCombine that made me nervous.

Prevously we returned the two operands of the compare part of the abs pattern. The RHS is always going to be a 0i, 1 or -1 constant. This isn't a very meaningful thing to return for any one. There's also some freedom in the abs pattern as to what happens when the value is equal to 0. This freedom led to early cse failing to match when different constants were used in otherwise equivalent operations. By returning the input and its negation in a defined order we can ensure an exact match. This also makes sure both patterns use the exact same subtract instruction for the negation. I believe CSE should evebntually make this happen and properly merge the nsw/nuw flags. But I'm not familiar with CSE and what order it does things in so it seemed like it might be good to really enforce that they were the same.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332865 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Analysis/ValueTracking.h
lib/Analysis/ValueTracking.cpp
lib/Transforms/Scalar/EarlyCSE.cpp
test/Transforms/EarlyCSE/commute.ll