[all-commits] [llvm/llvm-project] ee71c1: [X86] Implement smarter instruction lowering for F...

Simon Pilgrim via All-commits all-commits at lists.llvm.org
Wed Jul 14 04:04:07 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ee71c1bbccb19ed7a30b9aaf112a2c6ac2987193
      https://github.com/llvm/llvm-project/commit/ee71c1bbccb19ed7a30b9aaf112a2c6ac2987193
  Author: Simon Pilgrim <llvm-dev at redking.me.uk>
  Date:   2021-07-14 (Wed, 14 Jul 2021)

  Changed paths:
    M llvm/lib/Target/X86/X86ISelLowering.cpp
    M llvm/lib/Target/X86/X86TargetTransformInfo.cpp
    M llvm/test/Analysis/CostModel/X86/fptoui.ll
    M llvm/test/CodeGen/X86/concat-cast.ll
    M llvm/test/CodeGen/X86/fptoui-sat-scalar.ll
    M llvm/test/CodeGen/X86/ftrunc.ll
    M llvm/test/CodeGen/X86/half.ll
    M llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
    M llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
    M llvm/test/CodeGen/X86/vec_cast3.ll
    M llvm/test/CodeGen/X86/vec_fp_to_int.ll
    M llvm/test/Transforms/SLPVectorizer/X86/fptoui.ll

  Log Message:
  -----------
  [X86] Implement smarter instruction lowering for FP_TO_UINT from f32/f64 to i32/i64 and vXf32/vXf64 to vXi32 for SSE2 and AVX2 by using the exact semantic of the CVTTPS2SI instruction.

We know that "CVTTPS2SI" returns 0x80000000 for out of range inputs (and for FP_TO_UINT, negative float values are undefined). We can use this to make unsigned conversions from vXf32 to vXi32 more efficient, particularly on targets without blend using the following logic:

small := CVTTPS2SI(x);
fp_to_ui(x) := small | (CVTTPS2SI(x - 2^31) & ARITHMETIC_RIGHT_SHIFT(small, 31))

Even on targets where "PBLENDVPS"/"PBLENDVB" exists, it is often a latency 2, low throughput instruction so this logic is applied there too (in particular for AVX2 also). It furthermore gets rid of one high latency floating point comparison in the previous lowering.

@TomHender checked the correctness of this for all possible floats between -1 and 2^32 (both ends excluded).

Original Patch by @TomHender (Tom Hender)

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




More information about the All-commits mailing list