[PATCH] D12866: [InstCombine] fold zexts and constants into a phi (PR24766)

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 15:54:35 PDT 2015


spatel created this revision.
spatel added reviewers: nicholas, hfinkel, majnemer.
spatel added a subscriber: llvm-commits.

This is one step towards solving PR24766: 
https://llvm.org/bugs/show_bug.cgi?id=24766

We were not producing the same IR for these two C functions because the store to the temp bool causes extra zexts:
   #include <stdbool.h>
   
   bool switchy(char x1, char x2, char condition) {
      bool conditionMet = false;
      switch (condition) {
      case 0: conditionMet = (x1 == x2); break;
      case 1: conditionMet = (x1 <= x2); break;
      }
      return conditionMet;
   }
   
   bool switchy2(char x1, char x2, char condition) {
      switch (condition) {
      case 0: return (x1 == x2);
      case 1: return (x1 <= x2);
      }
     return false;
   }

As noted in the code comments, this test case manages to avoid the more general existing phi optimizations where there are only 2 phi inputs or where there are no constant phi args mixed in with the casts ops. It seems like a corner case, but if we don't catch it, then I don't think we can get SimplifyCFG to further optimize towards the canonical form for this function shown in the bug report.

http://reviews.llvm.org/D12866

Files:
  lib/Transforms/InstCombine/InstCombineInternal.h
  lib/Transforms/InstCombine/InstCombinePHI.cpp
  test/Transforms/InstCombine/phi.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12866.34747.patch
Type: text/x-patch
Size: 5853 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150914/c69a671d/attachment.bin>


More information about the llvm-commits mailing list