[PATCH] D21190: [InstCombine] allow more than one use for vector cast folding with selects

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 16 10:48:20 PDT 2016

eli.friedman accepted this revision.
eli.friedman added a comment.
This revision is now accepted and ready to land.

This patch doesn't only apply to bitcasts, which can lead to gigantic codegen changes in some cases.  That isn't a new problem, though; consider:

  define void @min_max_trunc(<4 x float> %a, <4 x float> %b, <4 x i64> %c, <4 x i64> %d, <4 x i32>* %ptr1, <4 x i32>* %ptr2) {
    %cmp = fcmp olt <4 x float> %a, %b
    %bc1 = trunc <4 x i64> %c to <4 x i32>
    %bc2 = trunc <4 x i64> %d to <4 x i32>
    %sel1 = select <4 x i1> %cmp, <4 x i32> %bc1, <4 x i32> %bc2
    store <4 x i32> %sel1, <4 x i32>* %ptr1
    ret void

instcombine makes this generate much worse code for SSE2.  Although, I'm pretty sure we can blame SelectionDAG for some part of that because it's generating absolutely terrible code.  Feel free to just file a bug for this, but I'm pretty sure we need some sort of target-hook for this.

It would be nice to throw together a few testcases for zext/sext/trunc/sitofp/fptoui just to make sure we have coverage.

Otherwise LGTM.


More information about the llvm-commits mailing list