[PATCH] [llgo] irgen: fix canAvoid*

Peter Collingbourne peter at pcc.me.uk
Tue Dec 16 11:39:24 PST 2014


================
Comment at: irgen/ssa.go:702
@@ +701,3 @@
+		switch ref := ref.(type) {
+		case *ssa.Field:
+		case *ssa.Index:
----------------
Can you leave the `// ok` comment here? This would make it a little clearer that we intend to accept the referrer rather than falling through.

================
Comment at: irgen/ssa.go:704
@@ +703,3 @@
+		case *ssa.Index:
+			if ref.X != ptr {
+				return false
----------------
(ignore this, phabricator is refusing to delete this comment)

================
Comment at: irgen/ssa.go:718
@@ -714,3 +717,3 @@
 func (fr *frame) canAvoidLoad(instr *ssa.UnOp, op llvm.Value) bool {
 	if fr.types.Sizeof(instr.Type()) < 16 {
 		// Don't bother with small values.
----------------
If we make this hard-coded constant something like 2*sizeof(int), we can probably be guaranteed that we will never need to check for indexes below.

================
Comment at: irgen/ssa.go:733
@@ -729,3 +732,3 @@
 			esc = true
-		case *ssa.Field, *ssa.Index:
-			// ok
+		case *ssa.Field:
+		case *ssa.Index:
----------------
Likewise here.

================
Comment at: irgen/ssa.go:735
@@ +734,3 @@
+		case *ssa.Index:
+			if ref.X != instr {
+				return false
----------------
Note that (as far as I can tell) this comparison would always fail  because `instr` at this point cannot be an appropriate size to be used as an index. We might want to panic in the body of this if statement to make it clear what our assumptions are, or just revert this part.

http://reviews.llvm.org/D6676

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list