[PATCH] D39053: [Bitfield] Add more cases to making the bitfield a separate location

Strahinja Petrovic via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 1 09:51:06 PDT 2017


spetrovic added a comment.

I was looking if I can reslove this problem in backend. Example:

C code:

typedef struct {
	unsigned int f1 : 28;
	unsigned int f2 : 4;
	unsigned int f3 : 12;
} S5;

void foo(S5 *cmd) {
	cmd->f3 = 5;
}

. ll file (without the patch):

%struct.S5 = type { i48 }

define void @foo(%struct.S5* nocapture %cmd) local_unnamed_addr #0 {
entry:

  %0 = bitcast %struct.S5* %cmd to i64*
  %bf.load = load i64, i64* %0, align 4
  %bf.clear = and i64 %bf.load, -4293918721
  %bf.set = or i64 %bf.clear, 5242880
  store i64 %bf.set, i64* %0, align 4
  ret void

}

The load (%bf.load = load i64, i64* %0, align 4) is NON_EXTLOAD, and backend handles it later as unaligned load. So, maybe one of possible solutions in backend is for each architecture to try to catch node pattern and replace unaligned loads with normal loads in specific cases, but I'm not sure how feasible that is. At the moment, the solution in frontend seems better to me. What do you think?


https://reviews.llvm.org/D39053





More information about the cfe-commits mailing list