[llvm] r320647 - [EarlyCSE] add tests for swapped abs/nabs; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 13 14:19:41 PST 2017
Author: spatel
Date: Wed Dec 13 14:19:40 2017
New Revision: 320647
URL: http://llvm.org/viewvc/llvm-project?rev=320647&view=rev
Log:
[EarlyCSE] add tests for swapped abs/nabs; NFC
Modified:
llvm/trunk/test/Transforms/EarlyCSE/commute.ll
Modified: llvm/trunk/test/Transforms/EarlyCSE/commute.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/EarlyCSE/commute.ll?rev=320647&r1=320646&r2=320647&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/EarlyCSE/commute.ll (original)
+++ llvm/trunk/test/Transforms/EarlyCSE/commute.ll Wed Dec 13 14:19:40 2017
@@ -218,3 +218,41 @@ define i8 @smax_nsw(i8 %a, i8 %b) {
ret i8 %r
}
+define i8 @abs_swapped(i8 %a) {
+; CHECK-LABEL: @abs_swapped(
+; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, %a
+; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i8 %a, 0
+; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i8 %a, 0
+; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 %a, i8 [[NEG]]
+; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[NEG]], i8 %a
+; CHECK-NEXT: [[R:%.*]] = or i8 [[M2]], [[M1]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %neg = sub i8 0, %a
+ %cmp1 = icmp sgt i8 %a, 0
+ %cmp2 = icmp slt i8 %a, 0
+ %m1 = select i1 %cmp1, i8 %a, i8 %neg
+ %m2 = select i1 %cmp2, i8 %neg, i8 %a
+ %r = or i8 %m2, %m1
+ ret i8 %r
+}
+
+define i8 @nabs_swapped(i8 %a) {
+; CHECK-LABEL: @nabs_swapped(
+; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, %a
+; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 %a, 0
+; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i8 %a, 0
+; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 %a, i8 [[NEG]]
+; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[NEG]], i8 %a
+; CHECK-NEXT: [[R:%.*]] = xor i8 [[M2]], [[M1]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %neg = sub i8 0, %a
+ %cmp1 = icmp slt i8 %a, 0
+ %cmp2 = icmp sgt i8 %a, 0
+ %m1 = select i1 %cmp1, i8 %a, i8 %neg
+ %m2 = select i1 %cmp2, i8 %neg, i8 %a
+ %r = xor i8 %m2, %m1
+ ret i8 %r
+}
+
More information about the llvm-commits
mailing list