[PATCH] D26556: [InstCombine] don't widen most selects by hoisting an extend

Filipe Cabecinhas via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 15 15:21:55 PST 2016


filcab added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstructionCombining.cpp:805
+  auto isNonTruncVariable = [](Value *V) {
+    return !isa<Constant>(V) && !match(V, m_Trunc(m_Value()));
+  };
----------------
Do you want to match type sizes, though? Or at least make sure you're truncating more (or the same) as you're extending?
Like this:
```[build-debug]% cat | ./bin/opt -O3 - -o - -S
define <4 x i64> @g3vec(<4 x i32> %_a, <4 x i1> %cmp) {
  %a = trunc <4 x i32> %_a to <4 x i24>
  %sel = select <4 x i1> %cmp, <4 x i24> %a, <4 x i24> <i24 42, i24 42, i24 42, i24 42>
  %ext = zext <4 x i24> %sel to <4 x i64>
  ret <4 x i64> %ext
}


; ModuleID = '<stdin>'
source_filename = "<stdin>"

; Function Attrs: norecurse nounwind readnone
define <4 x i64> @g3vec(<4 x i32> %_a, <4 x i1> %cmp) local_unnamed_addr #0 {
  %1 = and <4 x i32> %_a, <i32 16777215, i32 16777215, i32 16777215, i32 16777215>
  %2 = zext <4 x i32> %1 to <4 x i64>
  %ext = select <4 x i1> %cmp, <4 x i64> %2, <4 x i64> <i64 42, i64 42, i64 42, i64 42>
  ret <4 x i64> %ext
}

attributes #0 = { norecurse nounwind readnone }
```
vs just `select` + `zext` (using `sext` will make it even worse :-)



https://reviews.llvm.org/D26556





More information about the llvm-commits mailing list