This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Add tests for add nuw + uaddo
ClosedPublic

Authored by dlrobertson on Mar 17 2019, 9:15 AM.

Details

Diff Detail

Event Timeline

dlrobertson created this revision.Mar 17 2019, 9:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2019, 9:15 AM
lebedev.ri added inline comments.
llvm/test/Transforms/InstCombine/uadd-with-overflow.ll
3

Please run this test input through -instnamer first, and then strreplace tmp with t.
Else update script may get confused, or the output will be confusing to read.

https://godbolt.org/z/bX1_Os

lebedev.ri added inline comments.Mar 17 2019, 9:23 AM
llvm/test/Transforms/InstCombine/uadd-with-overflow.ll
87–96

Also add test with plain add.

dlrobertson marked 2 inline comments as done.Mar 17 2019, 9:35 AM

@lebedev.ri Both of your comments would also be valid for the tests for D58881. Should I update the tests there too?

llvm/test/Transforms/InstCombine/uadd-with-overflow.ll
3

Thanks! Good to know

87–96

Will do.

@lebedev.ri Both of your comments would also be valid for the tests for D58881. Should I update the tests there too?

That would be nice i guess.

  • add test for a wrapped add
  • don't use unnamed values in tests
lebedev.ri accepted this revision.Mar 17 2019, 10:27 AM

LG

llvm/test/Transforms/InstCombine/uadd-with-overflow.ll
55

You could also add variations with non-splat non-undef constants

This revision is now accepted and ready to land.Mar 17 2019, 10:27 AM
dlrobertson marked an inline comment as done.Mar 17 2019, 12:20 PM
dlrobertson added inline comments.
llvm/test/Transforms/InstCombine/uadd-with-overflow.ll
55

I'm not sure I follow. Wouldn't a non-splat non-undef variation of this test be something like simple_fold on line 10?

lebedev.ri added inline comments.Mar 17 2019, 12:25 PM
llvm/test/Transforms/InstCombine/uadd-with-overflow.ll
55

I meant something like

%a = add nuw <2 x i32> %x, <i32 12, i32 13> ; not splat, but still no overflow, but won't get folded
%b = tail call { <2 x i32>, <2 x i1> } @llvm.uadd.with.overflow.v2i32(<2 x i32> %a, <2 x i32> <i32 30, i32 30>)
%a = add nuw <2 x i32> %x, <i32 12, i32 4294967280> ; not splat, overflow
%b = tail call { <2 x i32>, <2 x i1> } @llvm.uadd.with.overflow.v2i32(<2 x i32> %a, <2 x i32> <i32 30, i32 255>)
nikic added inline comments.Mar 18 2019, 12:57 PM
llvm/test/Transforms/InstCombine/uadd-with-overflow.ll
55

To clarify terminology: "Splat" here means that all elements of a vector constant are the same (or undef, in which case we may assume them to be the same). Non-splat is if the elements differ. For many optimizations only the splat case is supported, because it is handled by matchers like m_APInt(). Handling non-splat cases typically requires using ConstantExpr based operations (instead of much more convenient APInt ones), so mostly nobody bothers...

lebedev.ri added inline comments.Mar 18 2019, 1:01 PM
llvm/test/Transforms/InstCombine/uadd-with-overflow.ll
55

Right, i should have explained that. I didn't get that at first too.

dlrobertson marked an inline comment as not done.

Added non-undef non-splat overflow and non-overflow tests

dlrobertson marked an inline comment as done.Mar 18 2019, 1:50 PM
dlrobertson added inline comments.
llvm/test/Transforms/InstCombine/uadd-with-overflow.ll
55

Ah yeah I was confusing vector and splat. Thanks updated the patch.

This revision was automatically updated to reflect the committed changes.