[llvm] 5933475 - [SimplifyCFG] Add test requiring only hoisting a branch.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 12 14:30:10 PDT 2021


Author: Florian Hahn
Date: 2021-04-12T22:29:34+01:00
New Revision: 59334755e4c8eea88f1541e7fbefb1b25ac094c2

URL: https://github.com/llvm/llvm-project/commit/59334755e4c8eea88f1541e7fbefb1b25ac094c2
DIFF: https://github.com/llvm/llvm-project/commit/59334755e4c8eea88f1541e7fbefb1b25ac094c2.diff

LOG: [SimplifyCFG] Add test requiring only hoisting a branch.

Added: 
    

Modified: 
    llvm/test/Transforms/SimplifyCFG/common-code-hoisting.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/SimplifyCFG/common-code-hoisting.ll b/llvm/test/Transforms/SimplifyCFG/common-code-hoisting.ll
index ff42d1b3e2711..c8bdba512ee22 100644
--- a/llvm/test/Transforms/SimplifyCFG/common-code-hoisting.ll
+++ b/llvm/test/Transforms/SimplifyCFG/common-code-hoisting.ll
@@ -108,3 +108,50 @@ for.end:
 return:
   ret void
 }
+
+; A example where only the branch instructions from %if.then2 and %if.end3 need
+; to be hoisted, which effectively replaces the original branch in %if.end. As
+; this does not add any new instructions to the hoist location, it should always be profitable.
+define float @clamp_float_value(float %value, float %minimum_value, float %maximum_value) {
+; HOIST-LABEL: @clamp_float_value(
+; HOIST-NEXT:  entry:
+; HOIST-NEXT:    [[CMP:%.*]] = fcmp ogt float [[VALUE:%.*]], [[MAXIMUM_VALUE:%.*]]
+; HOIST-NEXT:    [[CMP1:%.*]] = fcmp olt float [[VALUE]], [[MINIMUM_VALUE:%.*]]
+; HOIST-NEXT:    [[MINIMUM_VALUE_VALUE:%.*]] = select i1 [[CMP1]], float [[MINIMUM_VALUE]], float [[VALUE]]
+; HOIST-NEXT:    [[RETVAL_0:%.*]] = select i1 [[CMP]], float [[MAXIMUM_VALUE]], float [[MINIMUM_VALUE_VALUE]]
+; HOIST-NEXT:    ret float [[RETVAL_0]]
+;
+; NOHOIST-LABEL: @clamp_float_value(
+; NOHOIST-NEXT:  entry:
+; NOHOIST-NEXT:    [[CMP:%.*]] = fcmp ogt float [[VALUE:%.*]], [[MAXIMUM_VALUE:%.*]]
+; NOHOIST-NEXT:    br i1 [[CMP]], label [[RETURN:%.*]], label [[IF_END:%.*]]
+; NOHOIST:       if.end:
+; NOHOIST-NEXT:    [[CMP1:%.*]] = fcmp olt float [[VALUE]], [[MINIMUM_VALUE:%.*]]
+; NOHOIST-NEXT:    br i1 [[CMP1]], label [[RETURN]], label [[IF_END3:%.*]]
+; NOHOIST:       if.end3:
+; NOHOIST-NEXT:    br label [[RETURN]]
+; NOHOIST:       return:
+; NOHOIST-NEXT:    [[RETVAL_0:%.*]] = phi float [ [[VALUE]], [[IF_END3]] ], [ [[MAXIMUM_VALUE]], [[ENTRY:%.*]] ], [ [[MINIMUM_VALUE]], [[IF_END]] ]
+; NOHOIST-NEXT:    ret float [[RETVAL_0]]
+;
+entry:
+  %cmp = fcmp ogt float %value, %maximum_value
+  br i1 %cmp, label %if.then, label %if.end
+
+if.then:                                          ; preds = %entry
+  br label %return
+
+if.end:                                           ; preds = %entry
+  %cmp1 = fcmp olt float %value, %minimum_value
+  br i1 %cmp1, label %if.then2, label %if.end3
+
+if.then2:                                         ; preds = %if.end
+  br label %return
+
+if.end3:                                          ; preds = %if.end
+  br label %return
+
+return:                                           ; preds = %if.end3, %if.then2, %if.then
+  %retval.0 = phi float [ %maximum_value, %if.then ], [ %minimum_value, %if.then2 ], [ %value, %if.end3 ]
+  ret float %retval.0
+}


        


More information about the llvm-commits mailing list