[PATCH] D45448: [CVP] simplify phi with constant incoming values that match common variable edge values
    Florian Hahn via Phabricator via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Mon Apr  9 13:45:19 PDT 2018
    
    
  
fhahn added inline comments.
================
Comment at: test/Transforms/CorrelatedValuePropagation/phi-common-val.ll:4
+
+define i8* @simplify_phi_common_value_op0(i8* %ptr, i32* %b) {
+; CHECK-LABEL: @simplify_phi_common_value_op0(
----------------
It looks like the reason we miss those cases is that we are missing the links between the null constants in the comparison and the PHI node. 
Now, if we would have something like the code below, GVN could handle it.
```
define i8* @simplify_phi_common_value_op0(i8* %ptr, i32* %b, i8* %cmp) {
entry:
  %null.v = call i8* @llvm.ssa.copy.p0i8(i8* null)
  %isnull = icmp eq i8* %ptr, %cmp
  br i1 %isnull, label %return, label %else
else:                                             ; preds = %entry
  %lb = load i32, i32* %b
  %add = add nsw i32 %lb, 1
  store i32 %add, i32* %b
  br label %return
return:                                           ; preds = %else, %entry
  ret i8* %ptr
}
```
Unfortunately I don't think we have an easy way to get to that. In theory, I think should be able to annotate constants with the possible variables they are equal to, similar to what PredicateInfo does. Then we could use that to check if a constant is equal to a helpful variable. But that is a long shot and also (much) more work than this solution.
https://reviews.llvm.org/D45448
    
    
More information about the llvm-commits
mailing list