[PATCH] D90681: [CostModel] fix cost calc bug for sadd/ssub with overflow

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 3 06:16:10 PST 2020


spatel created this revision.
spatel added reviewers: samparker, RKSimon, pengfei, dmgreen.
Herald added a subscriber: mcrosier.
Herald added a project: LLVM.
spatel requested review of this revision.

As noted in D90554 <https://reviews.llvm.org/D90554>, there's an opcode typo in using an easily misused cost model API: getCmpSelInstrCost(). Beyond that, the assumed sequence of ops is questionable, but that would be another patch.

My guess is that the x86 test diffs show that we are probably wrong both before and after this change, so there will be no practical difference.
As an example, I tried this test which shows a cost of '7' either way:

  define <4 x i32> @sadd(<4 x i32> %va, <4 x i32> %vb) {
    %V4I32  = call {<4 x i32>, <4 x i1>}  @llvm.sadd.with.overflow.v4i32(<4 x i32> %va, <4 x i32> %vb)
    %ov = extractvalue {<4 x i32>, <4 x i1>} %V4I32, 1
    %r = extractvalue {<4 x i32>, <4 x i1>} %V4I32, 0
    %z = select <4 x i1> %ov, <4 x i32> <i32 42, i32 42, i32 42, i32 42>, <4 x i32> %r
    ret <4 x i32> %z
  }
  
  $ llc -o - sadd.ll -mattr=avx
  	vpaddd	%xmm1, %xmm0, %xmm2
  	vpcmpgtd	%xmm2, %xmm0, %xmm0
  	vpxor	%xmm0, %xmm1, %xmm0
  	vblendvps	%xmm0, LCPI0_0(%rip), %xmm2, %xmm0


https://reviews.llvm.org/D90681

Files:
  llvm/include/llvm/CodeGen/BasicTTIImpl.h
  llvm/test/Analysis/CostModel/X86/arith-overflow.ll
  llvm/test/Analysis/CostModel/X86/arith-ssat.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90681.302557.patch
Type: text/x-patch
Size: 75577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201103/07332764/attachment.bin>


More information about the llvm-commits mailing list