diff options
| author | Duncan Sands <baldrick@free.fr> | 2010-11-07 16:12:23 +0000 | 
|---|---|---|
| committer | Duncan Sands <baldrick@free.fr> | 2010-11-07 16:12:23 +0000 | 
| commit | f532d31198e7b1a878a8b71e5c1327966a0d3637 (patch) | |
| tree | 9b842bef0694237e97e6aeffb18a3464cb4c98bf /llvm/lib | |
| parent | 20b11eaa0140c995d78deec463ca45cdc52ea4ef (diff) | |
| download | bcm5719-llvm-f532d31198e7b1a878a8b71e5c1327966a0d3637.tar.gz bcm5719-llvm-f532d31198e7b1a878a8b71e5c1327966a0d3637.zip  | |
Fix a README item: when doing a comparison with the result
of a select instruction, see if doing the compare with the
true and false values of the select gives the same result.
If so, that can be used as the value of the comparison.
llvm-svn: 118378
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 23 | ||||
| -rw-r--r-- | llvm/lib/Target/README.txt | 12 | 
2 files changed, 21 insertions, 14 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index b49b4d0c6ab..1955802cc6e 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -252,8 +252,27 @@ Value *llvm::SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,        break;      }    } -   -   + +  // If the comparison is with the result of a select instruction, check whether +  // comparing with either branch of the select always yields the same value. +  if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS)) { +    // Make sure the select is on the LHS. +    if (!isa<SelectInst>(LHS)) { +      std::swap(LHS, RHS); +      Pred = CmpInst::getSwappedPredicate(Pred); +    } +    SelectInst *SI = cast<SelectInst>(LHS); +    // Now that we have "icmp select(cond, TV, FV), RHS", analyse it. +    // Does "icmp TV, RHS" simplify? +    if (Value *TCmp = SimplifyICmpInst(Pred, SI->getTrueValue(), RHS, TD)) +      // It does!  Does "icmp FV, RHS" simplify? +      if (Value *FCmp = SimplifyICmpInst(Pred, SI->getFalseValue(), RHS, TD)) +        // It does!  If they simplified to the same value, then use it as the +        // result of the original comparison. +        if (TCmp == FCmp) +          return TCmp; +  } +    return 0;  } diff --git a/llvm/lib/Target/README.txt b/llvm/lib/Target/README.txt index 55c08173d20..e63df536ae0 100644 --- a/llvm/lib/Target/README.txt +++ b/llvm/lib/Target/README.txt @@ -1963,15 +1963,3 @@ bb3:            ; preds = %entry          ret i32 %b  }  //===---------------------------------------------------------------------===// -We should fold this code into "ret i1 false" since neither %zero nor %one can -ever be null pointers. - -define i1 @foo(i1 %cond) { -  %zero = alloca i32 -  %one = alloca i32 - -  %ptr = select i1 %cond, i32* %zero, i32* %one -  %isnull = icmp eq i32* %ptr, null -  ret i1 %isnull -} -//===---------------------------------------------------------------------===//  | 

