1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=gvn -gvn-add-phi-translation=true -S < %s | FileCheck %s --check-prefix=ADD-TRANS-ON
3 ; RUN: opt -passes=gvn -gvn-add-phi-translation=false -S < %s | FileCheck %s --check-prefix=ADD-TRANS-OFF
5 ; Test that phi translation is able to hoist a load whose address
6 ; depends on an add also being hoisted.
7 define double @phi_translation_hoists_add(ptr %a, i64 %idx) {
8 ; ADD-TRANS-ON-LABEL: @phi_translation_hoists_add(
9 ; ADD-TRANS-ON-NEXT: entry:
10 ; ADD-TRANS-ON-NEXT: [[ADD_PHI_TRANS_INSERT:%.*]] = add nuw nsw i64 [[IDX:%.*]], 1
11 ; ADD-TRANS-ON-NEXT: [[GEP_PHI_TRANS_INSERT:%.*]] = getelementptr inbounds double, ptr [[A:%.*]], i64 [[ADD_PHI_TRANS_INSERT]]
12 ; ADD-TRANS-ON-NEXT: [[LOAD_PRE:%.*]] = load double, ptr [[GEP_PHI_TRANS_INSERT]], align 8
13 ; ADD-TRANS-ON-NEXT: br label [[FOR_BODY:%.*]]
14 ; ADD-TRANS-ON: for.body:
15 ; ADD-TRANS-ON-NEXT: [[CMP:%.*]] = fcmp ole double [[LOAD_PRE]], 1.000000e+00
16 ; ADD-TRANS-ON-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[FOR_BODY]]
18 ; ADD-TRANS-ON-NEXT: ret double [[LOAD_PRE]]
20 ; ADD-TRANS-OFF-LABEL: @phi_translation_hoists_add(
21 ; ADD-TRANS-OFF-NEXT: entry:
22 ; ADD-TRANS-OFF-NEXT: br label [[FOR_BODY:%.*]]
23 ; ADD-TRANS-OFF: for.body:
24 ; ADD-TRANS-OFF-NEXT: [[ADD:%.*]] = add nuw nsw i64 [[IDX:%.*]], 1
25 ; ADD-TRANS-OFF-NEXT: [[GEP:%.*]] = getelementptr inbounds double, ptr [[A:%.*]], i64 [[ADD]]
26 ; ADD-TRANS-OFF-NEXT: [[LOAD:%.*]] = load double, ptr [[GEP]], align 8
27 ; ADD-TRANS-OFF-NEXT: [[CMP:%.*]] = fcmp ole double [[LOAD]], 1.000000e+00
28 ; ADD-TRANS-OFF-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[FOR_BODY]]
29 ; ADD-TRANS-OFF: exit:
30 ; ADD-TRANS-OFF-NEXT: ret double [[LOAD]]
35 for.body: ; preds = %for.body, %entry
36 %add = add nuw nsw i64 %idx, 1
37 %gep = getelementptr inbounds double, ptr %a, i64 %add
38 %load = load double, ptr %gep
39 %cmp = fcmp ole double %load, 1.000000e+00
40 br i1 %cmp, label %exit, label %for.body