Skip to content

Commit b5d1f83

Browse files
authored
Update PHI node example to use proper semantics
1 parent 0a357ec commit b5d1f83

File tree

1 file changed

+0
-8
lines changed

1 file changed

+0
-8
lines changed

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ let function = builder.addFunction(
103103
let entryBB = function.appendBasicBlock(named: "entry")
104104
builder.positionAtEnd(of: entryBB)
105105

106-
// allocate space for a local value
107-
let local = builder.buildAlloca(type: FloatType.double, name: "local")
108-
109106
// Compare to the condition
110107
let test = builder.buildICmp(function.parameters[0], IntType.int1.zero(), .notEqual)
111108

@@ -120,15 +117,13 @@ builder.buildCondBr(condition: test, then: thenBB, else: elseBB)
120117
builder.positionAtEnd(of: thenBB)
121118
// local = 1/89, the fibonacci series (sort of)
122119
let thenVal = FloatType.double.constant(1/89)
123-
builder.buildStore(thenVal, to: local)
124120
// Branch to the merge block
125121
builder.buildBr(mergeBB)
126122

127123
// MARK: Else Block
128124
builder.positionAtEnd(of: elseBB)
129125
// local = 1/109, the fibonacci series (sort of) backwards
130126
let elseVal = FloatType.double.constant(1/109)
131-
builder.buildStore(elseVal, to: local)
132127
// Branch to the merge block
133128
builder.buildBr(mergeBB)
134129

@@ -147,16 +142,13 @@ This program generates the following IR:
147142
```llvm
148143
define double @calculateFibs(i1) {
149144
entry:
150-
%local = alloca double
151145
%1 = icmp ne i1 %0, false
152146
br i1 %1, label %then, label %else
153147
154148
then: ; preds = %entry
155-
store double 0x3F8702E05C0B8170, double* %local
156149
br label %merge
157150
158151
else: ; preds = %entry
159-
store double 0x3F82C9FB4D812CA0, double* %local
160152
br label %merge
161153
162154
merge: ; preds = %else, %then

0 commit comments

Comments
 (0)