[llvm] r214892 - Optimize vector fabs of bitcasted constant integer values.

Chandler Carruth chandlerc at google.com
Tue Aug 5 11:41:21 PDT 2014


On Tue, Aug 5, 2014 at 10:35 AM, Sanjay Patel <spatel at rotateright.com>
wrote:

>  ; PR20354: when generating code for a vector fabs op,
> -; make sure the correct mask is used for all vector elements.
> -; CHECK-LABEL: .LCPI4_0:
> -; CHECK-NEXT:    .long 2147483647
> -; CHECK-NEXT:    .long 2147483647
> -define i64 @fabs_v2f32(<2 x float> %v) {
> -; CHECK-LABEL: fabs_v2f32:
> -; CHECK:         movabsq $-9223372034707292160, %[[R:r[^ ]+]]
> -; CHECK-NEXT:    vmovq %[[R]], %[[X:xmm[0-9]+]]
> -; CHECK-NEXT:    vandps   {{.*}}.LCPI4_0{{.*}}, %[[X]], %[[X]]
> -; CHECK-NEXT:    vmovq   %[[X]], %rax
> -; CHECK-NEXT:    retq
> -  %highbits = bitcast i64 9223372039002259456 to <2 x float> ;
> 0x8000_0000_8000_0000
> -  %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %highbits)
> -  %ret = bitcast <2 x float> %fabs to i64
> -  ret i64 %ret
> +; make sure that we're only turning off the sign bit of each float value.
> +; No constant pool loads or vector ops are needed for the fabs of a
> +; bitcasted integer constant; we should just return an integer constant
> +; that has the sign bits turned off.
> +;
> +; So instead of something like this:
> +;    movabsq (constant pool load of mask for sign bits)
> +;    vmovq   (move from integer register to vector/fp register)
> +;    vandps  (mask off sign bits)
> +;    vmovq   (move vector/fp register back to integer return register)
> +;
> +; We should generate:
> +;    mov     (put constant value in return register)
> +
> +; CHECK-LABEL: fabs_v2f32_1
> +define i64 @fabs_v2f32_1() {
> + %bitcast = bitcast i64 18446744069414584320 to <2 x float> ;
> 0xFFFF_FFFF_0000_0000
> + %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %bitcast)
> + %ret = bitcast <2 x float> %fabs to i64
> + ret i64 %ret
> +; CHECK: movabsq $9223372032559808512, %rax
> +;  # imm = 0x7FFF_FFFF_0000_0000
> +}
>

I would strongly prefer that you follow the style of FileCheck patterns I
used. Specifically, please check the entire sequence of instructions.

Also, rather than the weird '# imm' comment, I think we should just check
the verbose asm comment that produces the readable hex form. Using
FileCheck against the verbose asm comments just leads to more readable and
maintainable tests, even if its good to not always rely on them (in case
they contain a bug somehow).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140805/5f99f69c/attachment.html>


More information about the llvm-commits mailing list