@@ -376,10 +376,12 @@ struct WgToSgElementwiseOp : public ConversionPattern {
376376 // Copy all attributes, but update "layout_result_0" to drop
377377 // sgLayout/sgData
378378 for (auto attr : op->getAttrs ()) {
379- if (auto layout = dyn_cast<xegpu::LayoutAttr>(attr.getValue ()))
380- state.addAttribute (attr.getName (), layout.dropSgLayoutAndData ());
381- else
379+ if (auto layout = dyn_cast<xegpu::LayoutAttr>(attr.getValue ())) {
380+ if (auto newLayout = layout.dropSgLayoutAndData ())
381+ state.addAttribute (attr.getName (), newLayout);
382+ } else {
382383 state.addAttribute (attr.getName (), attr.getValue ());
384+ }
383385 }
384386 Operation *newOp = rewriter.create (state);
385387 newResults.push_back (newOp->getResult (0 ));
@@ -629,8 +631,10 @@ void XeGPUWgToSgDistributePass::runOnOperation() {
629631 std::string name = xegpu::getLayoutName (result);
630632 if (auto layout = op->getAttrOfType <xegpu::LayoutAttr>(name)) {
631633 op->removeAttr (name);
632- if (!isa<scf::IfOp, scf::ForOp, scf::WhileOp, scf::ConditionOp>(op))
633- op->setAttr (name, layout.dropSgLayoutAndData ());
634+ if (!isa<scf::IfOp, scf::ForOp, scf::WhileOp, scf::ConditionOp>(op)) {
635+ if (auto newLayout = layout.dropSgLayoutAndData ())
636+ op->setAttr (name, newLayout);
637+ }
634638 }
635639 }
636640 });
0 commit comments