This is an archive of the discontinued LLVM Phabricator instance.

[test cases] add test cases for find more abs pattern
ClosedPublic

Authored by shchenz on Jul 9 2018, 7:19 PM.

Details

Summary

two more abs pattern and canonicalize abs pattern, this is for D48754
1:

define i32 @abs_canonical_6(i32 %a, i32 %b) {
  %tmp1 = sub i32 %a, %b
  %cmp = icmp sgt i32 %tmp1, -1
  %tmp2 = sub i32 %b, %a
  %abs = select i1 %cmp, i32 %tmp1, i32 %tmp2
  ret i32 %abs
}

this should be |a-b|.

2:

define <2 x i8> @abs_canonical_7(<2 x i8> %a, <2 x i8 > %b) {
  %tmp1 = sub <2 x i8> %a, %b
  %cmp = icmp sgt <2 x i8> %tmp1, <i8 -1, i8 -1>
  %tmp2 = sub <2 x i8> %b, %a
  %abs = select <2 x i1> %cmp, <2 x i8> %tmp1, <2 x i8> %tmp2
  ret <2 x i8> %abs
}

this should be |a-b| for vector type

3:

define i32 @abs_canonical_8(i32 %a) {
; CHECK-LABEL: @abs_canonical_8(
; CHECK-NEXT:    [[TMP:%.*]] = sub i32 0, [[A:%.*]]
; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP]], 0
; CHECK-NEXT:    [[ABS:%.*]] = select i1 [[CMP]], i32 [[A]], i32 [[TMP]]
; CHECK-NEXT:    ret i32 [[ABS]]
;
  %tmp = sub i32 0, %a
  %cmp = icmp slt i32 %tmp, 0
  %abs = select i1 %cmp, i32 %a, i32 %tmp
  ret i32 %abs
}

this should be |-a| -> |a|

Also add test cases for -|a-b|(i32 and vector), -|-a|(-|a|)

Diff Detail

Event Timeline

shchenz created this revision.Jul 9 2018, 7:19 PM
shchenz edited the summary of this revision. (Show Details)
shchenz edited the summary of this revision. (Show Details)
shchenz edited the summary of this revision. (Show Details)Jul 9 2018, 7:25 PM

The summary text description doesn't match the tests that are being added. The 'sgt -1' cases already exist as "@abs_canonical_2" and @nabs_canonical_2"?

llvm/test/Transforms/InstCombine/abs-1.ll
149

This is just verifying that the code does not change?

shchenz edited the summary of this revision. (Show Details)Jul 10 2018, 6:53 AM

@spatel Hi Sanjay, thanks very much for your comment. I have updated the description. For duplicated test case issue, "@abs_canonical_2" and @nabs_canonical_2" is for |x|, but my three case is for |-a|, |a-b| for int and vector. I am not clear you mean which one is duplicated?

llvm/test/Transforms/InstCombine/abs-1.ll
149

This case is for later abs pattern finding in D48754. with current master branch, there is no change to this code. I can surely add some other pred like sle to icmp to test some canonicalization for icmp. But I think this is not this test's purpose, so I let it unchanged. Should every case need changed even it is a baseline for later patch?

spatel accepted this revision.Jul 10 2018, 7:14 AM

@spatel Hi Sanjay, thanks very much for your comment. I have updated the description. For duplicated test case issue, "@abs_canonical_2" and @nabs_canonical_2" is for |x|, but my three case is for |-a|, |a-b| for int and vector. I am not clear you mean which one is duplicated?

Ah, I missed that the icmp in abs_canonical_8() is with the negated value. LGTM.

This revision is now accepted and ready to land.Jul 10 2018, 7:14 AM
spatel closed this revision.Jul 11 2018, 8:44 AM

This patch was committed, but Phab did not recognize the formatting in the commit message (leading spaces on each line?), so it didn't close this review:
rL336752

@spatel , thanks Sanjay for closing this item. Yes, I add two spaces in front of every line manually. I think there should be no need to do that.